不知道你有沒有遇過在建立新分支後,第一次 git push 時,總是會跳出下面這個錯誤訊息,說沒有設定 upstream 分支,導致你要先執行特定指令後才能順利 push?
git push fatal: The current branch
has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin <branch>To have this happen automatically for branches without a tracking upstream, see ‘push.autoSetupRemote’ in ‘git help config’.
在 Git 2.37 版本之後,你可以透過設定 push.autoSetupRemote 來讓 Git 自動在你 git push 時,幫你設定好 upstream,省去要手動執行 git push -u origin <branch> 的額外步驟。
# 預設情況下是 false,可以透過下面指令設定為 true
git config --global push.autoSetupRemote true
這樣在你建立新分支並第一次執行 git push 時,Git 就會自動幫你設定好 upstream 分支囉!