git push.default = current和push.default = upstream有什么区别? [英] What is the difference between git push.default=current and push.default=upstream?
问题描述
git-config的手册页列出了push.default的这些选项:
nothing - 不要推任何东西。
匹配 - 推送所有匹配的分支。所有在两端具有相同名称的分支都被认为是匹配的。这是默认设置。
upstream - 将当前分支推送至其上游分支。
跟踪 - 已弃用的上游同义词。
current - 将当前分支推送到同名的分支。
在大多数情况下,我会假设推送到分支的上游分支将与推送到因为上游分支通常具有相同的名称,并且因为相同名称的分支(当前)通常(或者总是按照定义?)在上游。那么有什么区别?
更新 : git-config的手册页已经更新(正如人们所期望的那样),所以区分作了这里现在可能会更清晰。
您已经总结了您的问题中的差异。 上游
推送到配置的上游分支,而当前
假定上游分支具有相同名称作为当前本地分支,并推送到该特定名称。实际上,没有理由认为本地分行的上游追踪分行与本地分行本身的名称相同。例如,如果您在多个存储库或跨多个共享开发人员远程工作,则通常最终会跟踪同一分支的不同分支,如 allen-master
或 susan-master
,它们都跟踪 master
分支艾伦和苏珊的回购分别。在这种情况下, current
将是不正确的设置,因为这些分支名称不存在于其遥控器上。然而, upstream
可以正常工作。
更实际的例子可能是跟踪开发
和生产
存储库。您的工作流可能会为每个分支使用不同的主线分支,但这可能会令人困惑。假设您是代码集成商,并且希望分别跟踪两个存储库的 master
分支。
git checkout -b production --track production / master
git checkout -b development --track development / master
现在你有两个分支机构跟踪它们各自的存储库,它们都没有使用 master
命名约定。关于分支名称几乎没有混淆:他们明确描述了他们跟踪的内容。然而, push.default = current
没有任何意义,因为这两个远程都不包含开发
或生产
分支。
The man page for git-config lists these options for push.default:
nothing - do not push anything.
matching - push all matching branches. All branches having the same name in both ends are considered to be matching. This is the default.
upstream - push the current branch to its upstream branch.
tracking - deprecated synonym for upstream.
current - push the current branch to a branch of the same name.
In most cases I would assume that pushing to a branch's upstream branch would be the same as pushing to a branch of the same name, since the upstream branch would normally have the same name, and since the branch of the same name ("current") would normally (or always, by definition?) be upstream. So what's the difference?
UPDATE: The man page for git-config has been updated (as one would expect), so the distinctions made there may be a lot clearer now.
You've summarized the difference in your question. upstream
pushes to the configured upstream branch, while current
assumes the upstream branch has the same name as the current local branch, and pushes to that specific name. In reality, there's no reason to assume a local branch's upstream tracking branch has the same name as the local branch itself.
For example, if you work in multiple repositories or across many shared developer remotes, you often end up tracking different forks of the same branch, such as allen-master
or susan-master
, both of which track the master
branch in Allen and Susan's repos, respectively. In this case, current
would be the incorrect setting, because those branch names don't exist on their remotes. upstream
, however, would work just fine.
A more practical example might be tracking both a development
and production
repository. Your workflow might use a different mainline branch for each, but that might get confusing. Suppose you were a code integrator and wanted to track both repositories' master
branches separately.
git checkout -b production --track production/master
git checkout -b development --track development/master
Now you've got two branches that track their respective repositories, neither of which use the master
naming convention at all. There's little confusion about the branch names: They explicitly describe what they track. Nevertheless, push.default = current
wouldn't make any sense as neither remote contains a development
or production
branch.
这篇关于git push.default = current和push.default = upstream有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!