简体   繁体   English

单个 git 命令本地化所有远程分支

[英]Single git command to localize all remote branches

I want to create local branches for each remote branch我想为每个远程分支创建本地分支

git 分支

If I have 100 branches, it will not be practical.如果我有 100 个分支,那将不切实际。

So I do:所以我这样做:

git branch -r

To see the list of all remote branches and create the following commands查看所有远程分支的列表并创建以下命令

git checkout -b AAAAA --no-track origin/AAAAA
git checkout -b BBBBB --no-track origin/BBBBB
git checkout -b CCCCC --no-track origin/CCCCC
git checkout -b DDDDD --no-track origin/DDDDD
...

It does all I need.它做了我需要的一切。 But if I have 100 projects, it is still a tedious task.但如果我有 100 个项目,这仍然是一项乏味的任务。

Is there any single git command that does this job automatically for me?是否有任何单个 git 命令可以自动为我完成这项工作?

Note: The option --no-track is very vital for me.注意:选项--no-track对我来说非常重要。 This is because the repositories are converted from svn to git.这是因为存储库从 svn 转换为 git。 So, connecting to origin is not possible.因此,无法连接到原点。

I would do it like this, assuming it's origin :我会这样做,假设它的origin

git branch -r | grep origin | sed 's/.*origin\///' | while read branch; do
    git checkout -b $branch --no-track origin/$branch
done

Or, taking advantage of the way git stores remote references:或者,利用 git 存储远程引用的方式:

ls -1 .git/refs/remotes/origin/ | while read branch; do
    git checkout -b $branch --no-track origin/$branch
done

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

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