不存在上游分支时`git push --force`的行为

vvppvyoh  于 2023-06-04  发布在  Git
关注(0)|答案(1)|浏览(144)

当不存在上游分支时,git push --force的行为是什么?
我会得到像fatal: The current branch branch_name has no upstream branch这样的东西,就像普通的推送一样,还是会“强制”创建上游分支?

sr4lhrrt

sr4lhrrt1#

在git 2.40.0中,--force不会改变git push在没有设置上游的情况下(当没有设置push.defaultpush.autoSetupRemote配置时)的行为。

$ 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'.

相关问题