# 實例流程

##### 多人協作基本

人員A push 更新至遠端庫時發生錯誤:

```
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/redquinoa/health-checks.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
```

原因是另一個協作人員B 對同一個遠端分支 (branch)的同個檔案，有上傳 (push) 過其他較新的異動 (commit)。

人員A 處理流程如下：

1. 更新遠端分支至本地，並且與本地分支做合併: `git pull`
2. 上述的自動合併，如果發生 Automatic merge failed，繼續下面步驟，手動排除衝突的內容。
3. 檢視遠端分支最近做過哪些更動: 
    - `git log --graph --onleline --all`
    - `git log -p origin/master`
4. 手動修改衝突的檔案內容 
    - 檢視檔案包含 *&lt;&lt;&lt;&lt; HEAD* 與 *&gt;&gt;&gt;&gt;&gt;&gt; something* 標記的內容
5. 完成後執行檢查與再上傳 
    1. `git add`
    2. `git status`
    3. `git commit`
    4. `git push`

##### 更新遠端分支

Remote branch: refactor

1. `git checkout -b refactor` : 複製遠端分支至本地庫，並切換本地庫到這分支
2. 開始修改程式碼
3. `git commit -a -m "Something"` : 步驟 2, 3 可執行多次
4. `git push -u origin refactor` : 更新遠端庫，第一次上傳至遠端 branch 需要加上參數 `-u origin refactor` 之後再上傳可以忽略。