36

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.

Lucio
  • 4,083
  • 3
  • 42
  • 72
Matrosov Oleksandr
  • 23,195
  • 44
  • 142
  • 269

5 Answers5

51

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

VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755
  • 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
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 ;)

Community
  • 1
  • 1
MoOx
  • 7,413
  • 4
  • 35
  • 35
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 :)

A.D.
  • 41
  • 2
  • Nice, and even more to the point than my answer! Upvoted. Kind of reminds me of GitHub actions ;) – VonC Jul 08 '20 at 17:48
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

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
ᐅdevrimbaris
  • 660
  • 9
  • 19