英文:
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.default
和 push.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'.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论