简体   繁体   English

Git:如何获取单个远程分支并自动创建远程跟踪分支?

[英]Git: How to fetch a single remote branch and create a remote-tracking branch of it automatically?

git-fetch manual page says: git-fetch手册页说:

git fetch remote_repo

will update "remote-tracking branches" of all branches from the remote repository. 将从远程存储库更新所有分支的“远程跟踪分支”。

What if I only need fetch a single remote branch? 如果我只需要获取一个远程分支怎么办?

I try to run: 我试着跑:

git fetch remote_repo remote_branch

It just stores infomation into FETCH_HEAD instead of creating a "remote-tracking branch" named remote_repo/remote_branch . 它只是将信息存储到FETCH_HEAD而不是创建名为remote_repo/remote_branch的“远程跟踪分支”。

I know there is a solution: 我知道有一个解决方案:

git fetch remote_repo remote_branch:refs/remotes/remote_repo/remote_branch

But it's too verbose. 但它太冗长了。

Is there a simpler way to achieve this? 有没有更简单的方法来实现这一目标?

If the set of remote branches that you want to fetch is somewhat stable, you can edit remote.<name>.fetch with git-config to achieve that result: 如果要获取的远程分支集合稍微稳定,则可以使用git-config编辑remote.<name>.fetch以实现该结果:

git config remote.remote_repo.fetch remote_branch:refs/remotes/remote_repo/remote_branch

That config will be picked up as default when running a bare git fetch : 运行裸git fetch时,该配置将被默认选中:

remote.<name>.fetch
    The default set of "refspec" for git-fetch(1). See git-fetch(1).

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

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