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.
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.
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.
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 ;)
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!
-
Good point (+1) I have included this feature in my answer for more visibility. – VonC Nov 9 '17 at 15:52
-
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