push本地代码到github出错
$ 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.
網(wǎng)上搜索了下,是因?yàn)檫h(yuǎn)程repository和我本地的repository沖突導(dǎo)致的,而我在創(chuàng)建版本庫(kù)后,在github的版本庫(kù)頁(yè)面點(diǎn)擊了創(chuàng)建README.md文件的按鈕創(chuàng)建了說(shuō)明文檔,但是卻沒有pull到本地。這樣就產(chǎn)生了版本沖突的問(wèn)題。
有如下幾種解決方法:
1.使用強(qiáng)制push的方法:
$ git push -u origin master -f
這樣會(huì)使遠(yuǎn)程修改丟失,一般是不可取的,尤其是多人協(xié)作開發(fā)的時(shí)候。
2.push前先將遠(yuǎn)程repository修改pull下來(lái)
$ git pull origin master
$ git push -u origin master
3.若不想merge遠(yuǎn)程和本地修改,可以先創(chuàng)建新的分支:
$ git branch [name]
然后push
$ git push -u origin [name]
總結(jié)
以上是生活随笔為你收集整理的push本地代码到github出错的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Python3与OpenCV3.3 图像
- 下一篇: 计数原理,递推,求从左边能看到l个棒子,