0

My scenario:

I have two existing Git repos:

 Project-A
 Project-B

I have merged Project-A into Project-B via a subtree-merge with no issues. Mostly following the 3rd answer here:

How do you merge two Git repositories?

But I need to merge Project-A into a folder I made within Project-B. Not within Project-B itself. What I keep getting looks like this:

 Project-B
   - Components - self made folder via git add component/README
   - Project-A

The structure I need is this:

 Project-B
   - Components  - self made folder via git add component/README
      - Project-A

I've been merging Project-A from within the Components folder so I'm not sure why when I push I keep getting Project-A outside of Components?

Also, when I am merging Project A. I would like to merge all branches at the same time, I've been trying "git merge Project-A" but I get a message saying Git can't do that. So I have to do something like "git merge Project-A/master". But there are 20 different branches within Project-A that I need to push into the component folder. Possible to merge all branches at one time?

Thanks

Community
  • 1
  • 1
bschmitty
  • 1,118
  • 3
  • 16
  • 46

1 Answers1

1

You can use git subtree add --prefix=Components/Project-A <Project-A’s address> branchname to realize the secondly structure as you showed above.

And you can use git subtree push --prefix= Components/Project-A <Project-A’s address> branchname to push changes in / Components/Project-A directory to remote Project-A

Of cause, you can't use git merge Project-A or git merge Project-A/master successfully. Because things exist in Components/Project-A is not as a branch but as sub-project in your Project-B (you can use git branch to show the exist branches, you will find these branches are only belongs to Project-B). Since Project-A is not a branch, so can't merge anything about Project-A.

Marina Liu
  • 36,876
  • 5
  • 61
  • 74
  • I am able to push Project-A/master into Project B with the following: git merge -s ours --no-commit Project-A/master but isn't there a way to access and merge all the branches at one time. Something like: git merge -s ours --no-commit Project-A/all-branches..? – bschmitty Nov 17 '16 at 21:26
  • 1
    @bschmitty, I guess you used `git remote add Project-A ` add a remote. Only by this way, you can use git merge about Project-A. And it’s impossible to merge all branches at once, just like the concept of merge, it only affects two branches for one time. Hope it can help you:) – Marina Liu Nov 18 '16 at 07:35
  • @bschmitty, hi, have you get what you want? If yes, can you mark it as answer, since it will help who has similar question? BWT, there is no need to merge Project-A to Project-B, because you have already added Project-A's stuff in Project-B in step1, just commit for Project-B, it will contain stuff about Project-A – Marina Liu Nov 24 '16 at 06:54