Git 的@{upstream} 和@{push} 有何不同?

How do Git's @{upstream} and @{push} differ?

Git 分支的 @{upstream} 和较新的 @{push} 有什么区别?

据我了解,@{upstream} 是分支的上游跟踪引用,@{push}push 将推送到的引用。根据我的直觉,这些是同一回事。检查几个方便的分支 git rev-parse @{upstream}git rev-parse @{push} 相同,并且(我认为可能不会以相同的方式解析)git rev-parse --abbrev-ref @{upstream}git rev-parse --abbrev-ref @{push} 相同。

@{upstream}@{push} 确实指向同一件事... 当他们这样做时.

开个玩笑,我的意思是这只是巧合,这是两个配置条目指向同一个遥控器的结果,但它们可能不同。

this page 上有一个很好的例子。

具体来说,这部分:

The suffix @{push} reports the branch "where we would push to" if git push were run while branchname was checked out (or the current HEAD if no branchname is specified). Since our push destination is in a remote repository, of course, we report the local tracking branch that corresponds to that branch (i.e., something in refs/remotes/).

$ git config push.default current
$ git config remote.pushdefault myfork
$ git switch -c mybranch origin/master

$ git rev-parse --symbolic-full-name @{upstream}
refs/remotes/origin/master

$ git rev-parse --symbolic-full-name @{push}
refs/remotes/myfork/mybranch

Note in the example that we set up a triangular workflow, where we pull from one location and push to another. In a non-triangular workflow, @{push} is the same as @{upstream}, and there is no need for it.