剛建立的github版本庫,在push代碼時出錯:
$ git push -u origin master
To git@github.com:******/Demo.git
! [rejected] 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]git