Reputation: 349
I have three dirs with git repo :
-dir1
-dir2
-dir3
I want move dir1 and dir2 into dir3 :
-dir3
-dir1
-dir2
How i can merge git repo from dir1 and dir2 into dir3? I need save dir1 and dir2 vcs commits in dir3 history
Upvotes: 3
Views: 246
Reputation: 134591
You can use git subtree here.
First you have to read in the repository history by fetching them.
../dir3 $ git remote add rdir1 ../dir1
../dir3 $ git fetch rdir1
Then add the subtree of the remote to your repository.
../dir3 $ git switch master
../dir3 $ git subtree add -P dir1 rdir1/master
This takes the tree of the remote branch rdir1/master
and sets it to the local path dir1
so it becomes a subtree of your dir3 repo.
Then cleanup the remotes when finished
../dir3 $ git remote remove rdir1
Repeat for any other repos you wish to import.
Upvotes: 3