git 如何使现有分支跟踪远程分支?

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

How to make an existing branch track a remote branch?

gitgithubatlassian-sourcetree

提问by Mahmoud Adam

I'm trying to track an exiting branch to a remote branch using --trackor --set-upstream-to, but got the following error

我正在尝试使用--trackor将退出分支跟踪到远程分支--set-upstream-to,但出现以下错误

$ git branch --track master origin/master
fatal: A branch named 'master' already exists.   
$ git branch --set-upstream-to master origin/master
fatal: branch 'origin/master' does not exist   

I checked SourceTree and found that it uses --set-upstream, but got the following warning

我检查了 SourceTree 并发现它使用--set-upstream,但收到以下警告

$ git branch --set-upstream master origin/master
The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
Branch master set up to track remote branch master from origin.

Both --trackand --set-upstream-tois not working, Am I missing something?

双方--track--set-upstream-to没有工作,我失去了什么?

回答by Mahmoud Adam

I think I got it, it will be as the following (used --set-upstream-to + remote name)

我想我明白了,它将如下所示(使用 --set-upstream-to + 远程名称)

$ git branch --set-upstream-to origin/master
Branch master set up to track remote branch master from origin.