Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
588 views
in Technique[技术] by (71.8m points)

git - 让现有的Git分支跟踪一个远程分支?(Make an existing Git branch track a remote branch?)

I know how to make a new branch that tracks remote branches, but how do I make an existing branch track a remote branch?

(我知道如何创建一个跟踪远程分支的新分支,但是如何使现有分支跟踪远程分支?)

I know I can just edit the .git/config file, but it seems there should be an easier way.

(我知道我可以编辑.git/config文件,但似乎应该有一个更简单的方法。)

  ask by Pat Notz translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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`?)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...