git push.default=current 和 push.default=upstream 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11872984/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between git push.default=current and push.default=upstream?
提问by iconoclast
The man page for git-config lists these options for push.default:
git-config 的手册页列出了 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-confighas been updated (as one would expect), so the distinctions made theremay be a lot clearer now.
UPDATE:为的git-config中的男子页面已经更新(如人们所期望的),这样的区分做出有可能是一个更加清晰了。
采纳答案by Christopher
You've summarized the difference in your question. upstream
pushes to the configuredupstream branch, while current
assumes the upstream branch has the same name as the currentlocal 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.
您已经总结了问题的不同之处。upstream
推送到配置的上游分支,同时current
假设上游分支与当前本地分支具有相同的名称,并推送到该特定名称。实际上,没有理由假设本地分支的上游跟踪分支与本地分支本身具有相同的名称。
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.
例如,如果您在多个存储库中或跨多个共享的开发人员远程工作,您通常最终会跟踪同一分支的不同分支,例如allen-master
或susan-master
,它们分别跟踪master
Allen 和 Susan 的存储库中的分支。在这种情况下,current
将是不正确的设置,因为它们的遥控器上不存在这些分支名称。upstream
,但是,会工作得很好。
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.
一个更实际的例子可能是同时跟踪 adevelopment
和production
存储库。您的工作流可能会为每个工作流使用不同的主线分支,但这可能会让人感到困惑。假设您是一个代码集成商并且想要分别跟踪两个存储库的master
分支。
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.
现在您有两个分支来跟踪它们各自的存储库,它们master
都根本不使用命名约定。分支名称几乎没有混淆:它们明确描述了它们跟踪的内容。然而,push.default = current
没有任何意义,因为遥控器都不包含 adevelopment
或production
分支。
回答by Yawar
current
will push the current branch to a branch with the same name on the remote repo.
current
将当前分支推送到远程仓库上同名的分支。
upstream
will push the current branch to the upstream branch.
upstream
将当前分支推送到上游分支。
The upstream branch is a branch which has been explicitly or implicitly defined as being upstream from your current branch. That means that push and pull by default will sync with this branch. The upstream branch may be in the same repo as the current branch itself. You can do interesting things like set up your localmaster branch as upstream from your localfeature (topic) branch, and push and pull between them.
上游分支是一个明确或隐含地定义为当前分支上游的分支。这意味着默认情况下推和拉将与此分支同步。上游分支可能与当前分支本身在同一个仓库中。您可以做一些有趣的事情,例如将本地主分支设置为本地功能(主题)分支的上游,并在它们之间进行推拉。
Implicit upstream setup is done through the branch.autosetupmerge
config value. You can find documentation in the git config
help page. Explicit upstream setup is done with the -u
option to the git branch
command. See the help page for details.
隐式上游设置是通过branch.autosetupmerge
配置值完成的。您可以在git config
帮助页面中找到文档。显式上游设置是通过命令-u
选项完成的git branch
。有关详细信息,请参阅帮助页面。