简体   繁体   English

如何在git上进行git setup跟踪分支

[英]How to have git setup tracking branch on pull

There are times when I'm pulling new changes from a repo that someone else changed. 有时候,我会从另一个仓库更改的仓库中提取新更改。 They have created new branches and pushed them to the central repo. 他们创建了新的分支并将其推到中央仓库。 Is there a way, when pulling these new branches, to get git to automatically create tracking branches of the same name locally? 当拉出这些新分支时,是否有办法让git自动在本地创建相同名称的跟踪分支?

I don't think git supports this out of the box. 我不认为git开箱即用。

In case if this is only for one branch, you could do: 如果仅针对一个分支,则可以执行以下操作:

git fetch origin branch_name && git checkout -b branch_name --track origin/branch_name

You could also create a git alias for the above, by adding the following to your ~/.gitconfig file: 您还可以通过将以下内容添加到~/.gitconfig文件中,为上述内容创建一个git别名:

[alias]
    fetch_tracking = "!f() { git fetch origin $1 && git checkout -b $1 --track origin/$1; }; f"

and then call it using 然后使用

git fetch_tracking branch_name

Of course, you would do the above the first time only. 当然,您只会在第一次时执行上述操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM