Erogol Erogol - 2 months ago 12
Git Question

How to use Bitbucket and GitHub at the same time for one project?

I have one repository which I want to push into Bitbucket and GitHub.
It is vital for my repository to be hosted by both.

Is there a way to do this in Git?

Answer

You can use multiple remote repositories with git. Check this: http://gitref.org/remotes/

But you'll have to push separately into 2 of your remotes I believe.

For example, if your project currently points to github, you can rename your current remote repository to github:

$ git remote rename origin github

You can then add another remote repository, say bitbucket:

$ git remote add bitbucket git@bitbucket.org:your_user/your_repo.git

Now in order to push changes to corresponding branch on github or bitbucket you can do this:

$ git push github HEAD
$ git push bitbucket HEAD

Same rule applies to pulling: you need to specify which remote you want to pull from:

$ git pull github your_branch
$ git pull bitbucket your_branch