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