我有一個Bash函數來防止推送到沒有上游分支的遠程存儲庫(例如GitHub)時的錯誤。也許你熟悉這個錯誤:切換到git config push.default current有什麼影響?
$ git checkout -b test
$ git push
fatal: The current branch test has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin test
爲了解決這個問題,我做的是攔截到git push
任何電話,看看我得到與沒有上游分支的錯誤。在出現這種錯誤的情況下,我的終端會自動爲我執行它,而不是複製並粘貼上面的建議命令。
這是代碼,如果你是好奇: https://github.com/arturoherrero/dotfiles/blob/6f517a0b7287ac61174dfd2b6c9ee5bf9a9c2e96/system/git.sh#L22-L34
我現在的Git的配置是push.default simple
,但今天我剛剛意識到,我可以使用push.default current
來實現相同的行爲(除我的自定義代碼)。
Ref。 https://www.kernel.org/pub/software/scm/git/docs/git-config.html
current - push the current branch to update a branch with the same name on the receiving end. Works in both central and non-central workflows.
simple - in centralized workflow, work like upstream with an added safety to refuse to push if the upstream branch’s name is different from the local one.
When pushing to a remote that is different from the remote you normally pull from, work as current. This is the safest option and is suited for beginners.
This mode has become the default in Git 2.0.
那麼,什麼是切換到git config push.default current
影響?我想了解一些可能出現問題的情況,因爲Git具有不同的行爲。