在使用git push -u origin master命令将本地的仓库和远程仓库进行同步时出现了以下错误:
$ git push -u origin master
To github.com:runla/MainPageDemo.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:runla/MainPageDemo.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.
原因:
Updates were rejected because the tip of your current branch is behind这句话的意思是说远程仓库的分支比本地的仓库的代码还要新,因此会有冲突
解决方法:
git push -f origin master(多人协作时慎重使用)
$ git push -f origin master
Counting objects: 86, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (55/55), done.
Writing objects: 100% (86/86), 105.27 KiB | 0 bytes/s, done.
Total 86 (delta 8), reused 0 (delta 0)
remote: Resolving deltas: 100% (8/8), done.
To github.com:runla/MainPageDemo.git
+ 527d8c2...d12366e master -> master (forced update)