--- title: Git 簡易操作流程 tags: git --- # Git 簡易操作流程 ## 設定 git 本機切換到要同步 git 的資料夾,將資料 clone 下來 * `git clone https://xxxxxxxxxxx` :::info clone 下來之後就會預設 pull default branch 了 ::: ## 作業流程 ### 1. 取得 git 文件最新版本 `git pull origin main` ### 2. 開個分支 `git checkout -b feat/homepage` (假設分支是 feat/homepage) :::info * feat/ 前綴代表為功能 * branch_name 可自訂名稱,例如用自己的 github 帳號當名稱 ::: ### 3. 開發~ ### 4. 開發完成後 將檔案推送回 git #### (1) 將檔案加入 git 中 `git add 檔案名稱` // 可指定特定檔案 或 `git add . ` // 會一次加入所有變更過的檔案 #### (2) 撰寫 commit message `git commit` :::info 可使用 `npx git-cz` 代替 (參考就好) ::: ##### commit message 範例 主要描述這個 commit 做了什麼事,例如修改 Home page: `Update: HomePage` #### ==(3) 在 merge 之前先取得最新的 origin== `git fetch origin` #### ==(4) 切換到到 main!== `git checkout main` #### ==(5) 把自己的分之 merge 到 main!== `git merge feat/homepage` (假設分支是 feat/homepage) #### (6) 切換回自己的分支,將結果 push 至 git `git checkout feat/homepage` (假設分支是 feat/homepage) `git push` :::info * 第一次執行應該會出現一行指令叫你打,類似: `git push --set-upstream origin xxxxxxx` 照著打送出即可(這只有第一次要打,以後只要打 `git push` 即可) ::: #### (5) 輸入 github 帳號密碼,輸入後便會完成 push ### 5. push 成功之後要上去 [github](https://github.com/) 建立 pull request #### (1) 按下Pull Request 再按下new pull request  #### (2) 在 base repository 選 main  #### (4) 右邊的 compare: 選擇你的分支 feat/xxxxx #### (5) 按下create new pull request 就完成了 :::info ### 【重要】接下來每次翻譯的步驟: 1. 切換到 main `git checkout main` 2. 取得最新 tw `git fetch origin` `git pull` 3. 從最新的 tw 開分支出來開發 `git checkout -b lang/****` (自己設的分支) 4. 重覆「[4. 開發完成後 將檔案推送回 git](# 4. 開發完成後 將檔案推送回 git)」的操作 ### Remark: code review 後的修改 ==PR後,如需修改。修改完直接接「[4. 翻譯完成後 將檔案推送回 git](#4-翻譯完成後-將檔案推送回-git)」== ::: ## 其他常用 git 指令 ### 查看目前本機的 git 狀態 `git status` ### 查看目前的分支 `git branch` ### 放棄本機所有變更(以遠端 git 資料覆蓋本機資料) `git reset --hard origin/tw` ## 參考資源 * [為你自己學 Git](https://gitbook.tw):git 指令教學 * [連猴子都能懂的 Git 入門指南](https://backlog.com/git-tutorial/tw/) * [Fork](https://git-fork.com):a fast and friendly git client for Mac and Windows * [Learn Git Branching](https://learngitbranching.js.org/?locale=zh_TW) ==推薦!線上練習git概念==
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up