Bulk Move remote git branches from one directory to another

Viewed 23

I need to bulk move remote git branches from one directory to another

My current setup:

remote:
      Origin
            bug 
               bug1_abcbug
               bug2_xyzbug
               .
               .
               .
               bug50_bug
            
            bugfix
                bug51
                bug52
                .
                .
                .
                Bug200

Now, I want to move all 50 branches from the 'bug' folder to the 'bugfix' folder. I know I can individually rename the branch name and its remote name. However, is there any easier way to just bulk move all branches from one folder to another ?

Thanks in Advance

1 Answers

You can do this in 3 steps:

  1. Run git fetch
  2. Identify the command to isolate the 50 branches. In your example it might be something like (in a *nix shell):
git branch -r | grep origin/bug/bug
  1. Loop through the list of branches, and for each branch name, use your tool of choice to parse out the branch name after the 1st '/' character (bug/bug1...), and again after the 2nd '/' character (bug1...), and then use those strings in conjunction with this command (or function) to rename the branch remotely:
git push <remote> <remote>/<old_name>:refs/heads/<new_name> :<old_name>
Related