How to make a GitHub mirror to Bitbucket?

23,405

Solution 1

You could simply add a second remote:

git remote add bitbucket /url/to/am/empty/bitbucket/repo

and push everything to bitbucket:

git push --mirror bitbucket

You can actually pull from or push to multiple remotes from your local repo.


Update 2020:

As noted below in Rahulmohan Kolakandy's answer, if you are talking about an on-premise BitBucket server (as opposed to bitbucket.org), then you can take advantage of BitBucket Server Smart Mirroring.

As commented by V-Q-A NGUYEN:

BitBucket Server Smart Mirroring (introduced originally in 2016, and Oct. 2017 for BitBucket Server)

is only available for customers with an active Bitbucket Data Center license

Solution 2

The method explained here is better https://stackoverflow.com/a/12795747/988941

git remote set-url origin --add https://bitbucket.org/YOU/YOUR_REPO.git

Recent version of git handle multiple URLs in the same origin ;)

Solution 3

With Bitbucket Server, you can use ScriptRunner https://marketplace.atlassian.com/apps/1213250/scriptrunner-for-bitbucket-server-stash?hosting=server&tab=overview

Full Disclosure: I work for them :)

Solution 4

you no longer have to create these mirror links. Bitbucket has come up with this concept of smart mirror which does a real time sync to your mirror server.

More read here https://confluence.atlassian.com/bitbucketserver/smart-mirroring-776640046.html

Hope this helps!

Solution 5

You can also check the following (copy pasted from links below) ;

From How to properly mirror a git repository, you can use

git clone --mirror [email protected]/upstream-repository.git

cd upstream-repository.git

git push --mirror [email protected]/new-location.git

Or you can follow Duplicating a repository;

Open Terminal and create a bare clone of the repository.

git clone --bare https://github.com/exampleuser/old-repository.git

Mirror-push to the new repository.

cd old-repository.git
git push --mirror https://github.com/exampleuser/new-repository.git

Remove the temporary local repository you created in step 1.

cd ..
rm -rf old-repository.git
Share:
23,405
Matrosov Oleksandr
Author by

Matrosov Oleksandr

Updated on July 31, 2022

Comments

  • Matrosov Oleksandr
    Matrosov Oleksandr almost 2 years

    I have a repo that I've cloned from GitHub and want to have a mirror of this repo on BitBucket. Is there is any way how to do it? Something like having two origin in the repo as I think.

  • VonC
    VonC over 6 years
    Good point (+1) I have included this feature in my answer for more visibility.
  • V-Q-A NGUYEN
    V-Q-A NGUYEN about 4 years
    BitBucket Server Smart Mirroring feature is only available for customers with an active Bitbucket Data Center license
  • VonC
    VonC about 4 years
    @V-Q-ANGUYEN Thank you, good point. I have included your comment in the answer for more visibility.
  • VonC
    VonC almost 4 years
    Nice, and even more to the point than my answer! Upvoted. Kind of reminds me of GitHub actions ;)