git--step by step

雄獅歸來

剛創建的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.

網上搜索了下,是因為遠程repository和我本地的repository沖突導致的,而我在創建版本庫后,在github的版本庫頁面點擊了創建README.md文件的按鈕創建了說明文檔,但是卻沒有pull到本地。這樣就產生了版本沖突的問題。

有如下幾種解決方法:

1.使用強制push的方法:

$ git push -u origin master -f

這樣會使遠程修改丟失,一般是不可取的,尤其是多人協作開發的時候。

2.push前先將遠程repository修改pull下來

$git pull origin master

$ git push -u origin master

3.若不想merge遠程和本地修改,可以先創建新的分支:

$git branch [name]

然后push

$git push -u origin [name]

參考:

http://stackoverflow.com/questions/10298291/cannot-pushto-github-keeping-saying-need-merge

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容