Git:如何获取一个远程分支并自动创建一个远程分支? [英] Git: How to fetch a single remote branch and create a remote-tracking branch of it automatically?
问题描述
git fetch remote_repo
将更新远程存储库中所有分支的远程跟踪分支。
如果我只需要获取一个远程分支,该怎么办? / p>
我尝试运行:
git fetch remote_repo remote_branch
它只是将信息存储到 FETCH_HEAD
中,而不是创建一个 remote-tracking branch命名为 remote_repo / remote_branch
。
我知道有一个解决方案:
git fetch remote_repo remote_branch:refs / remotes / remote_repo / remote_branch
但它太冗长了。
有没有更简单的方法来实现它?
如果您想要fet的一组远程分支ch有点稳定,你可以用 git-config
编辑 remote。< name> .fetch
来达到这个结果:
git config remote.remote_repo.fetch remote_branch:refs / remotes / remote_repo / remote_branch
运行裸露 git fetch
时,该配置将被默认选为默认值:
remote。< name> .fetch
git-fetch(1)的默认设置refspec。请参阅git-fetch(1)。
git-fetch manual page says:
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
.
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.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
:
remote.<name>.fetch
The default set of "refspec" for git-fetch(1). See git-fetch(1).
这篇关于Git:如何获取一个远程分支并自动创建一个远程分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!