1. 首先,可以試圖用git push origin branch-name推送自己的修改;
2. 如果推送失敗,則因為遠程分支比你的本地更新,需要先用git pull試圖合並;如果git pull提示“no tracking information”,則說明本地分支和遠程分支的鏈接關系沒有創建,用命令git branch --set-upstream branch-name origin/branch-name。
3. 如果合並有沖突,則解決沖突,並在本地提交;
4. 沒有沖突或者解決掉沖突后,再用git push origin branch-name推送就能成功!
一次操作的流程:
$ git push origin dev
To git@xxxxxxxxxxxxxxxxxxxxxxxxEngine.git
! [rejected] dev -> dev (non-fast-forward)
error: failed to push some refs to 'git@xxxxxxxxxxxxxxxxxxxxxxxxEngine.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
推送失敗,因為別人最新提交和你試圖推送的提交有沖突,解決辦法也很簡單,Git已經提示我們,先用git pull把最新的提交從origin/dev抓下來,然后,在本地合並,解決沖突,再推送。
$ git pull
Auto-merging MetaDataUtils.java
CONFLICT (add/add): MetaDataUtils.java
git pull成功,但是合並有沖突,需要手動解決。
解決后,提交,再push:
$ git commit -m "merge & fix!"
$ git push origin dev