让现有的Git分支跟踪远程分支? [英] Make an existing Git branch track a remote branch?

查看:170
本文介绍了让现有的Git分支跟踪远程分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何创建一个追踪远程分支的新分支,但如何让现有分支追踪远程分支?

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

foo 和一个远程上游

>

从Git 1.8.0开始:

  git branch -u upstream / foo 

或者,如果本地分支 foo 不是当前分支:

  git branch -u upstream / foo foo 

或者,如果您想输入更长的命令,这些命令就相当于以上两个命令:

  git branch --set-upstream-to = upstream / foo 

git branch --set-upstream-to = upstream / foo foo

自Git 1.7.0开始:

  git branch --set-upstr eam foo upstream / foo 

注释:

所有上述命令都会导致本地分支 foo 跟踪远程分支 foo 从远程上游。旧的(1.7.x)语法不赞成使用新的(1.8+)语法。新的语法旨在更直观,更易于记忆。 为什么我需要始终执行`--set-upstream`?


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.

解决方案

Given a branch foo and a remote upstream:

As of Git 1.8.0:

git branch -u upstream/foo

Or, if local branch foo is not the current branch:

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 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. The old (1.7.x) syntax is deprecated in favor of the new (1.8+) syntax. The new syntax is intended to be more intuitive and easier to remember.


See also: Why do I need to do `--set-upstream` all the time?

这篇关于让现有的Git分支跟踪远程分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆