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
What does '--set-upstream' do?
提问by Евгений Масленков
What does git --set-upstream
do?
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 pull
command (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-upstream
is to use its shorthand flag -u
as 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
git
deprecate this somewhat ambiguous--set-upstream
option in favour of a more verbose--set-upstream-to
option with identical syntax and behaviourgit 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-upstream
flag 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 pull
or git push
in 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 fetch
,git pull
还是git push
在未来。它假设您希望保持本地分支和它正在跟踪的远程分支同步,并采取适当的措施来实现这一点。
You could achieve the same thing with git branch --set-upstream-to
or 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>>