git “--set-upstream”有什么作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18031946/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:42:12  来源:igfitidea点击:

What does '--set-upstream' do?

gitpushgit-pushgit-remoteupstream-branch

提问by Евгений Масленков

What does git --set-upstreamdo?

git 有--set-upstream什么作用?

I tried to understand it by reading the git manual, but I didn't quite get it.

我试图通过阅读git 手册来理解它,但我并没有完全理解它。

回答by TheCodeArtist

git branch --set-upstream <remote-branch>

sets the default remote branch for the current local branch.

为当前本地分支设置默认远程分支。

Any future git pullcommand (with the current local branch checked-out),
will attempt to bring in commits from the <remote-branch>into the current local branch.

任何未来的git pull命令(签出当前本地分支)
都将尝试将提交从<remote-branch>当前本地分支引入。



One way to avoid having to explicitly type --set-upstreamis to use its shorthand flag -uas follows:

避免必须显式键入的一种方法--set-upstream是使用其速记标志-u,如下所示:

git push -u origin local-branch

This sets the upstream association for any future push/pull attempts automatically.
For more details, checkout this detailed explanation about upstream branches and tracking.

这会自动为任何未来的推/拉尝试设置上游关联。
有关更多详细信息,请查看有关上游分支和跟踪的详细说明



To avoid confusion, recent versions of gitdeprecate this somewhat ambiguous --set-upstreamoption in favour of a more verbose --set-upstream-tooption with identical syntax and behaviour

git branch --set-upstream-to <origin/remote-branch>

为了避免混淆,最近版本的git弃用这个有点模棱两可的--set-upstream选项,转而--set-upstream-to使用具有相同语法和行为的更详细的选项

git branch --set-upstream-to <origin/remote-branch>

回答by Will

When you push to a remote and you use the --set-upstreamflag git sets the branch you are pushing to as the remote tracking branch of the branch you are pushing.

当您推送到远程并使用--set-upstream标志时,git会将您推送到的分支设置为您推送的分支的远程跟踪分支。

Adding a remote tracking branch means that git then knows what you want to do when you git fetch, git pullor git pushin future. It assumes that you want to keep the local branch and the remote branch it is tracking in sync and does the appropriate thing to achieve this.

添加远程跟踪分支意味着混帐就知道你想什么时候做什么git fetchgit pull还是git push在未来。它假设您希望保持本地分支和它正在跟踪的远程分支同步,并采取适当的措施来实现这一点。

You could achieve the same thing with git branch --set-upstream-toor git checkout --track. See the git help pages on tracking branchesfor more information.

您可以使用git branch --set-upstream-to或实现相同的目的git checkout --track。有关更多信息,请参阅有关跟踪分支的 git 帮助页面。

回答by Turbut Alin

git branch --set-upstream <<origin/branch>>is officially not supported anymore and is replaced by git branch --set-upstream-to <<origin/branch>>

git branch --set-upstream <<origin/branch>>正式不再受支持,取而代之的是git branch --set-upstream-to <<origin/branch>>