37

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.

5 Answers 5

52

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

2
  • BitBucket Server Smart Mirroring feature is only available for customers with an active Bitbucket Data Center license May 13, 2020 at 14:35
  • @V-Q-ANGUYEN Thank you, good point. I have included your comment in the answer for more visibility.
    – VonC
    May 13, 2020 at 15:15
9

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 ;)

4

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 :)

0
3

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!

1
  • Good point (+1) I have included this feature in my answer for more visibility.
    – VonC
    Nov 9, 2017 at 15:52
2

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
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.