0

I currently have a few GitHub repositories and would like to move those to the same repository, but on a different branch. It would be nice to maintain the histories for those repositories.

I believe it is a slight variation on the problem posted here because in my case I want to move multiple repositories to the same repository but on a different Branch.

So now I have something like this:

- Repository X  
- Repository Y  
- Repository Z

And I would like this:

- Repository A  
   |- Branch X  
   |- Branch Y  
   |- Branch Z

What would be the best way to go about that whilst maintaining repository history and contributes.

Floris
  • 41
  • 8
  • 1
    Possible duplicate of [How do you merge two Git repositories?](https://stackoverflow.com/questions/1425892/how-do-you-merge-two-git-repositories) – phd Jan 01 '18 at 18:29

1 Answers1

0
# go to your repository that you want to keep
cd RepositoryA
# fetch other repositories there
git remote add -f repositoryb [repository_b_address]
git remote add -f repositoryc [repository_c_address]
# push commits from other repositories to your main repo (repository_a)
git push origin repositoryb/master:refs/heads/branch_y
git push origin repositoryc/master:refs/heads/branch_z

For Git commit is a commit and it doesn't matter from which repo it came. Thus we're able to push unrelated graphs of commits into separate branches.

Stanislav Bashkyrtsev
  • 14,470
  • 7
  • 42
  • 45