0

I have two repositories, one in Bitbucket and the other in Github.

What I want to do is: merge Bitbucket's repository into Github repository while keeping the commit history of Bitbucket's repository. After merging, Github's repo should have its own commit history alongside Bitbucket's repository commit history. I would like to avoid creating a new repository in Github.

How do I do the above using git?

Richard
  • 7,037
  • 2
  • 23
  • 76

2 Answers2

0

You can try this

  • Clone GitHub repository

    git clone <github-repo-url>
    
  • Add Bitbucket repository as remote in the cloned repository

    git remote add <some-remote-name> <bitbucket-repo-url>
    
  • Merge the new remote branch with option --allow-unrelated-histories

    git fetch <some-remote-name>
    git merge --allow-unrelated-histories <remote-name>/<branch-name>
    
  • Push to GitHub remote with --force option

    git push --force <github-remote-name>
    

Note that the merge operations might lead to merge conflicts. You can have a look at this How do you merge two Git repositories? for more options.

Saurabh P Bhandari
  • 6,014
  • 1
  • 19
  • 50
0

You can take a look at git mirror here https://help.github.com/en/github/creating-cloning-and-archiving-repositories/duplicating-a-repository#mirroring-a-repository-in-another-location

It will allow you to automatically pull changes to github when you push to bitbucket.

Bilal Shah
  • 1,135
  • 7
  • 17
  • 42