0

Is it possible, using a Git Subtree Merge, to merge all branches of Repo B into Repo A at the same time, with one Git Command? Repo B has close to 15 different branches and I'm trying to save time by doing a sub merge of the repo and all of its branches at once. I haven't found any ways to do that online..is it not possible?

If not possible, does anybody know the most efficient way to merge each branch individually into parent Repo A. Repo B looks something like this:

 Repo B/masterbranch
 Repo B/developbranch
 Repo B/featurebranch

I need Repo A (the parent) to look something like this:

 Repo A
  component -> folder of some sort that holds the different branches
     masterbranch
     developbranch
     featurebranch

I know I can keep the history with the subTree merge so I'm thinking I need to do something in that regard. But it only seems possible to do it one branch at a time with causes file collisions in my .bowerrc

My initial tries of doing one file at a time has been from following this:

How do you merge two Git repositories?

Community
  • 1
  • 1
bschmitty
  • 710
  • 1
  • 10
  • 30
  • Are you saying, for the end product, you want "Repo A" to have a "component" directory with a separate *subdirectory* for each branch of "Repo B"? – K. A. Buhr Nov 30 '16 at 01:11
  • Just one "component" directory and within the directory I can select a specific branch and see its history. – bschmitty Nov 30 '16 at 20:03

1 Answers1

1

Yes, you can do it by two ways — submodules and add remote (without subtree):

By submodules:

  1. In repo A, add repo B as submodule, use git submodule add <URL for Repo B> component
  2. In the subfolder of component (cd component), you will find all the branches of Repo B (git branch -a). Now branches in Repo B exist as part of Repo A. You can switch to different branches of Repo B
  3. If you want the changes of Repo B submitted in Repo A, you need to go back to Repo A directory (cd ..), then use git commit and git push to Repo A. If you want changes of Repo B submitted in Repo B itself, you can in the component subfolder (cd component), then use git commit and git push.

By adding remote:

  1. Add Repo B remote in local Repo A, use git remote add origin1 <URL for Repo B>
  2. Pull Repo by git pull origin1
  3. But this maybe a bit different from your requirement, all the branches of Repo A and Repo B in the same directory, it appear as (git branch -a):

remotes/origin/<all Repo A branches> remotes/origin1/<all Repo B branches>

note: you can switch to any of the branch. If both Repo A and Repo B have master branch, you need to add remote name, such as git checkout origin/master or git checkout origin1/master

Marina Liu
  • 32,805
  • 4
  • 48
  • 60
  • I used the submodules method following the steps above...it did add Repo B as a submodule but the directory it created was "component @ 65c69279bb2" and it also created a ".gitmodules" folder. Can I just go ahead a rename that folder to "component"? Does that effect anything? Also, can I remove the .gitmodules folder or does that need to be there? – bschmitty Nov 30 '16 at 20:02
  • In the above comment I was submitting the changes of repo B into Repo A. This is what I need I just don't want the components folder to be named as it is above..if the gitmodule file has to be there I can live with that..thanks – bschmitty Nov 30 '16 at 20:44
  • It looks like I have to do it with the remote options. I see all the branches sitting there inside Repo A/component/ with this option...does a push do the same thing as the steps would do in my link above (i.e. read-tree --prefix=...) – bschmitty Dec 01 '16 at 01:21
  • Yes, all the branches of Repo B (not Repo A) sitting in `Repo A/component` – Marina Liu Dec 01 '16 at 01:49
  • 1
    You did found the name `component @ 65c69279bb2` on remote. But actually the directory’s name is `component`, it shows `component @ 65c69279bb2` on remote just to make it clearly that the submodule was added after the commit 65c69279bb2. You can verify by cloning again, use `git clone --recursive `. So you don’t need to rename it. The file of `.gitmodules` can’t be removed, because it defines the relationship between Repo A and Repo B. So just keep it there. Hope this can help you :) – Marina Liu Dec 01 '16 at 05:17
  • This method could work..but is there any way to rename the component folder so that it doesn't have the "@ 65c69279bb2"?...kind of messy looking with that there...Thanks – bschmitty Dec 02 '16 at 18:26
  • No, I’m afraid not. Actually the submodule name is already `component`, it just means **Submodule component added at 65c69279bb2** (you can click `add` link in GitHub to find it) – Marina Liu Dec 03 '16 at 04:20