Given a branch foo
and a remote upstream
:
(给定分支foo
和远程upstream
:)
As of Git 1.8.0:
(从Git 1.8.0开始:)
git branch -u upstream/foo
Or, if local branch foo
is not the current branch:
(或者,如果本地分支foo
不是当前分支:)
git branch -u upstream/foo foo
Or, if you like to type longer commands, these are equivalent to the above two:
(或者,如果您想键入更长的命令,这些命令等同于以上两个:)
git branch --set-upstream-to=upstream/foo
git branch --set-upstream-to=upstream/foo foo
As of Git 1.7.0:
(从Git 1.7.0开始:)
git branch --set-upstream foo upstream/foo
Notes:
(笔记:)
- All of the above commands will cause local branch
foo
to track remote branch foo
from remote upstream
. (以上所有的命令都将引起局部分支foo
跟踪远程分支foo
从远程upstream
。)
- The old (1.7.x) syntax is deprecated in favor of the new (1.8+) syntax.
(不推荐使用旧的(1.7.x)语法,而采用新的(1.8+)语法。)
The new syntax is intended to be more intuitive and easier to remember. (新语法旨在更直观,更易于记忆。)
- Defining the upstream will fail with newly created remotes that have not been fetched.
(使用尚未获取的新创建的遥控器定义上游将失败。)
In that case run git fetch upstream
beforehand. (在那种情况下,事先运行git fetch upstream
。)
See also: Why do I need to do `--set-upstream` all the time?
(另请参阅: 为什么我需要始终执行`--set-upstream`?)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…