1

I want to organize my git repos since multiple of them are highly related. Now I want to combine (not merge) all of them into one single repo with multiple branches and delete the old repos. What shall I do?

For example, I have repo A, B and C with branches A.master, A.branch1, B.master, C.master, C.branch2. What I want is to create a new repo D whose branches are D.master(something new), A.master(has to change name), A.branch1, B.master(has to change name), C.master(has to change name), C.branch2 with all the commit histories from the original repos. And then delete the A, B and C, so that submodule cannot be used.

junhuizh
  • 402
  • 5
  • 11
  • Yes, that is what you have to do: come up with new names where there are conflicts. What is your actual question? – torek Nov 29 '19 at 06:28
  • My question is how to do all of these combination. I want to combine different repos into one and keep all commit histories. How to do that? – junhuizh Nov 29 '19 at 06:51

2 Answers2

0

Suppose you have repo A, B, and C and you make a new repo D.
Assumed you will be checked out to the correct branch on which you will be merging
E.g.

$> cd A
$> git checkout master

then add remote for old repo branch to new repo

$> cd D
$> git remote add A "path to A"
$> git remote update

... at this point im just copy-pasting this answer Merge git repo into branch of another repo

rpeepz
  • 1
  • 2
  • Does this solution keep all of the commit histories? – junhuizh Nov 29 '19 at 08:08
  • did some quick digging and while I personally cannot confirm this for I have not tested, check out this answer describing something similar https://stackoverflow.com/questions/17371150/moving-git-repository-content-to-another-repository-preserving-history – rpeepz Nov 29 '19 at 09:15
0

Hope this helps.

One you created new repo called D.

  • commands to be run in the repo A
 1. git remote add repoD https://github.com/****/repod.git
 2. git checkout master (go to master branch of A)
 3. git co -b master_of_a
 4. git push -u repoD master_of_a

repeat the below steps for other branches in the repo A. Below example give for branch1 in the repo A

 1. git checkout branch1 (go to branch1 of A)
 3. git co -b branch1_of_a
 4. git push -u repoD branch1_of_a

  • repeat the above two steps for all the repos and all the branches.

yes. stores the commit history as well

Esha
  • 151
  • 8