Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 844
erogol Avatar asked Oct 18 '12 18:10

erogol


People also ask

Can we use both GitHub and Bitbucket?

You can use multiple remote repositories with git. But you'll have to push separately into 2 of your remotes I believe. Show activity on this post.

Can I use the same SSH key for GitHub and Bitbucket?

Yes it is. You tell git where the remote code lives from a per-repository configuration file. You can even push to GitHub and Bitbucket from the same repository if you want to. One important piece will be connecting to each separately with SSH.

How do I push to Bitbucket from GitHub?

To push to a Git repository At the command line, make sure you've changed into the repository directory. Enter git push at the command line to push your commits from your local repository to Bitbucket. To be specific about exactly where you're pushing, enter git push <remote_server> <branch_name>.


2 Answers

You can use multiple remote repositories with git. 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 [email protected]: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 
like image 71
Denis Kniazhev Avatar answered Sep 18 '22 04:09

Denis Kniazhev


Yes, you can do that. You don't have to push twice but just once to push to both remote repositories. I had the same issue before so wrote how to do it here. Git: Push to / Pull from Both Github and Bitbucket

like image 43
Kevin Lee Avatar answered Sep 21 '22 04:09

Kevin Lee