I want to create local branches for each remote branch
If I have 100 branches, it will not be practical.
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.
Is there any single git command that does this job automatically for me?
Note: The option --no-track
is very vital for me. This is because the repositories are converted from svn to git. So, connecting to origin is not possible.
I would do it like this, assuming it's 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:
ls -1 .git/refs/remotes/origin/ | while read branch; do
git checkout -b $branch --no-track origin/$branch
done
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.