`git push –force` 当没有上游分支存在时的行为

huangapple go评论67阅读模式
英文:

Behavior of `git push --force` when no upstream branch exists

问题

git push --force 当没有上游分支存在时的行为是什么?

我会得到类似于 fatal: 当前分支 branch_name 没有上游分支 的消息,就像正常推送时会发生的一样,还是会强制创建上游分支?

英文:

What's the behavior of git push --force when no upstream branch exists?

Will I get something like fatal: The current branch branch_name has no upstream branch, as would happen with a normal push, or would the upstream branch be "forcefully" created?

答案1

得分: 3

--force 不会改变 git push 在没有设置上游分支时的行为(当没有设置 push.defaultpush.autoSetupRemote 配置时),根据 git 2.40.0 的经验。

$ git checkout -b dev/test
切换到一个新分支 'dev/test'
$ git push
致命错误:当前分支 dev/test 没有上游分支。
要推送当前分支并设置远程分支为上游分支,请使用

    git push --set-upstream origin dev/test

要使没有跟踪上游分支的分支自动执行此操作,请参阅 'git help config' 中的 'push.autoSetupRemote'
$ git push --force
致命错误:当前分支 dev/test 没有上游分支。
要推送当前分支并设置远程分支为上游分支,请使用

    git push --set-upstream origin dev/test

要使没有跟踪上游分支的分支自动执行此操作,请参阅 'git help config' 中的 'push.autoSetupRemote'
英文:

--force does not change the behaviour of git push without an upstream set (when no push.default and push.autoSetupRemote config is set) empirically with git 2.40.0.

$ git checkout -b dev/test
Switched to a new branch 'dev/test'
$ git push
fatal: The current branch dev/test has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin dev/test

To have this happen automatically for branches without a tracking
upstream, see 'push.autoSetupRemote' in 'git help config'.

$ git push --force
fatal: The current branch dev/test has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin dev/test

To have this happen automatically for branches without a tracking
upstream, see 'push.autoSetupRemote' in 'git help config'.

huangapple
  • 本文由 发表于 2023年6月2日 03:04:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76384965.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定