3

I have twenty git repositories on github and I want to be able to create a branch in all the twenty repositories with one command or click (without going through to all the twenty repos manually one at a time).

I do understand that I may write a shell script to do that. I am wondering if I am able to utilize sub modules of if there is any other way? Not sure, any help is appreciated.

Arsalan Siddiqui
  • 181
  • 2
  • 11

1 Answers1

5

Considering you can push to multiple repositories at one, you could define in your local repo an remote "all" referencing those 20 repos, create a local orphan branch, and push that branch to "all"

If your branch is supposed to start from an existing branch, then submodules are indeed a better solution, as you might be talking about 20 different repositories, each one with their own existing history.

With a local repo referencing in a .gitmodules 20 repos, you can use (as in here) the git submodule foreach syntax in order to create and push that new branch (git checkout master; git checkout -b new_branch; git push -u origin new_branch, wrapped in a script as in this answer)

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I have a similar requirements. I have 10 different repos. For every work, i need to create the same branch in all repos. Do you think submodule is better option or it will be an overhead? – user2636464 Apr 04 '22 at 03:17
  • @user2636464 submodule is a good option, especially with the upcoming Git 2.36: https://stackoverflow.com/a/71195953/6309 and the new `git branch --recurse-submodules` command. – VonC Apr 04 '22 at 14:30
  • Thanks and nice to see your comments after many discussions around clearcase previously :) – user2636464 Apr 05 '22 at 04:27
  • @user2636464 Right! From 2013 to 2019. I still answer ClearCase questions to this day, although far less frequently. – VonC Apr 05 '22 at 06:31
  • yeah. we have also moved away decomissioning all things rational onto the other tools now. – user2636464 Apr 05 '22 at 07:25