Git 2.x 中g(shù)it push時(shí)遇到 push.default 警告的解決方法

最近在學(xué)習(xí)使用 git&GitHub,然后今天遇到了一個(gè)問(wèn)題。在執(zhí)行 git add 和 git commit 操作之后,再進(jìn)行 git push 操作,出現(xiàn)了如下提示:

$ 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

第一感覺(jué)是 FxxK 。
然后來(lái)看看這一長(zhǎng)串英文是在說(shuō)什么:

警告:push.default (默認(rèn)push)未設(shè)置;在Git 2.0 中,push.default 的值從‘matching’改為‘simple’了。消除此警告并保留以前的習(xí)慣,輸入:

git config --global push.default matching

消除此警告并采用新的設(shè)置值,輸入:

git config --global push.default simple

當(dāng) push.default 的值設(shè)置成 ‘matching’ ,git 將會(huì)推送所有本地已存在的同名分支到遠(yuǎn)程倉(cāng)庫(kù)
從 Git 2.0 開(kāi)始,git 采用更加保守的值'simple',只會(huì)推送當(dāng)前分支到相應(yīng)的遠(yuǎn)程倉(cāng)庫(kù),'git pull' 也將值更新當(dāng)前分支。
……(后面就不譯了)

已經(jīng)說(shuō)的很清楚了,Git 2.0 需要設(shè)置 push.default 的值,兩者的區(qū)別上面也說(shuō)了,所以我就采用新的保守值吧,輸入:

git config --global push.default simple

然而接下來(lái)執(zhí)行 git push 還是不頂用,因?yàn)樯厦婢娴氖莾蓚€(gè)問(wèn)題,于是再次提示:

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

還沒(méi)學(xué)到后面,就簡(jiǎn)單百度了一下,結(jié)果只是半懂,好像首次 push ,所以輸入以下命令即可:

git push -u origin master

之后再直接執(zhí)行 git push 就可以了。
</br>
參考文章:
Git 2.0 更改 push default 為 'simple'
在 GitHub 上管理項(xiàng)目

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開(kāi)發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見(jiàn)模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,558評(píng)論 19 139
  • https://segmentfault.com/a/1190000002783245 一直以來(lái)對(duì)git push...
    平謙閱讀 838評(píng)論 0 0
  • 風(fēng)雨同舟數(shù)十年 而今兩隔萬(wàn)重山 縱然心生千般苦 莫負(fù)夕陽(yáng)紅遍天 贈(zèng)周雪峰戰(zhàn)友2017.6.20
    秦漢追月閱讀 558評(píng)論 1 0
  • 采鹽的老男孩閱讀 277評(píng)論 0 1
  • 自在 如風(fēng) 都是別人在為你遮擋 在那些 你看不見(jiàn)的地方 某個(gè)時(shí)候
    程又臻閱讀 174評(píng)論 0 0

友情鏈接更多精彩內(nèi)容