近在學習使用 git&GitHub,然后今天遇到了一個問題。在執行 git add 和 git commit 操作之后,再進行 git push 操作,出現了如下提示:
$ git push
warning: push.default is unset; its implicit value has changed in Git 2.0 from 'matching' to 'simple'. To squelch this message and maintain the traditional behavior, use: git config --global push.default matching To squelch this message and adopt the new behavior now, use: git config --global push.default simple When push.default is set to 'matching', git will push local branches to the remote branches that already exist with the same name. Since Git 2.0, Git defaults to the more conservative 'simple' behavior, which only pushes the current branch to the corresponding remote branch that 'git pull' uses to update the current branch. See 'git help config' and search for 'push.default' for further information. (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode 'current' instead of 'simple' if you sometimes use older versions of Git) fatal: The current branch master has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin master
然后來看看這一長串英文是在說什么:
警告:push.default (默認push)未設置;在Git 2.0 中,push.default 的值從‘matching’改為‘simple’了。消除此警告並保留以前的習慣,輸入:
git config --global push.default matching
消除此警告並采用新的設置值,輸入:
git config --global push.default simple
當 push.default 的值設置成 ‘matching’ ,git 將會推送所有本地已存在的同名分支到遠程倉庫
從 Git 2.0 開始,git 采用更加保守的值'simple',只會推送當前分支到相應的遠程倉庫,'git pull' 也將值更新當前分支。
……(后面就不譯了)
已經說的很清楚了,Git 2.0 需要設置 push.default 的值,兩者的區別上面也說了,所以我就采用新的保守值吧,輸入:
git config --global push.default simple
然而接下來執行 git push 還是不頂用,因為上面警告的是兩個問題,於是再次提示:
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use git push --set-upstream origin master
還沒學到后面,就簡單百度了一下,結果只是半懂,好像首次 push ,所以輸入以下命令即可:
git push -u origin master
之后再直接執行 git push 就可以了。
作者:蘇之辛
鏈接:https://www.jianshu.com/p/e26175b2e916
來源:簡書
簡書著作權歸作者所有,任何形式的轉載都請聯系作者獲得授權並注明出處。