剛創(chuàng)建的github版本庫澎灸,在push代碼時出錯:
$ git push -u origin master
To git@github.com:******/Demo.git
? ?master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:******/Demo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
網(wǎng)上搜索了下蚣常,是因為遠程repository和我本地的repository沖突導(dǎo)致的梭伐,而我在創(chuàng)建版本庫后具被,在github的版本庫頁面點擊了創(chuàng)建README.md文件的按鈕創(chuàng)建了說明文檔,但是卻沒有pull到本地跟匆。這樣就產(chǎn)生了版本沖突的問題绪爸。
有如下幾種解決方法:
1.使用強制push的方法:
$ git push -u origin master -f
這樣會使遠程修改丟失蛉拙,一般是不可取的界睁,尤其是多人協(xié)作開發(fā)的時候觉增。
2.push前先將遠程repository修改pull下來
$git pull origin master
$ git push -u origin master
3.若不想merge遠程和本地修改,可以先創(chuàng)建新的分支:
$git branch [name]
然后push
$git push -u origin [name]
參考:
http://stackoverflow.com/questions/10298291/cannot-pushto-github-keeping-saying-need-merge