遠(yuǎn)程創(chuàng)建了含有Readme的倉(cāng)庫(kù), 本地初始化并添加了遠(yuǎn)程倉(cāng)庫(kù)后, push卻失敗了, 出現(xiàn)提示:
$ git push origin dev
To https://git.oschina.net/erchoc/laradock.git
! [rejected] dev -> dev (fetch first)
error: failed to push some refs to 'https://git.oschina.net/erchoc/laradock.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
問(wèn)題(Non-fast-forward)的出現(xiàn)原因是: git倉(cāng)庫(kù)中已有一部分代碼, 它不允許你直接把你的代碼覆蓋上去仍源。于是你有2個(gè)選擇方式:
1. 強(qiáng)推心褐,即利用強(qiáng)覆蓋方式用你本地的代碼替代git倉(cāng)庫(kù)內(nèi)的內(nèi)容: git push -f
2. 先把git的東西fetch到你本地然后merge后再push
- $ git fetch
- $ git merge
這2句命令等價(jià)于
$ git pull
可是, 有時(shí)候還會(huì)出現(xiàn)問(wèn)題:
上面出現(xiàn)的 [branch "master"]是需要明確(.git/config)如下的內(nèi)容
[branch "master"]
remote = origin
merge = refs/heads/master
這等于告訴git2件事:
1,當(dāng)你處于master branch, 默認(rèn)的remote就是origin笼踩。
2逗爹,當(dāng)你在master branch上使用git pull時(shí),沒(méi)有指定remote和branch嚎于,那么git就會(huì)采用默認(rèn)的remote(也就是origin)來(lái)merge在master branch上所有的改變
如果不想或者不會(huì)編輯config文件的話掘而,可以在bush上輸入如下命令行:
$ git config branch.master.remote origin
$ git config branch.master.merge refs/heads/master
之后再重新git pull下。最后git push你的代碼吧匾旭。