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

- 1,262,500
- 529
- 4,410
- 5,250
-
BitBucket Server Smart Mirroring feature is only available for customers with an active Bitbucket Data Center license – V-Q-A NGUYEN May 13 '20 at 14:35
-
@V-Q-ANGUYEN Thank you, good point. I have included your comment in the answer for more visibility. – VonC May 13 '20 at 15:15
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 ;)
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 :)

- 41
- 2
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!

- 107
- 1
- 3
-
Good point (+1) I have included this feature in my answer for more visibility. – VonC Nov 09 '17 at 15:52
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 git@example.com/upstream-repository.git
cd upstream-repository.git
git push --mirror git@example.com/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

- 718
- 9
- 20