Ahmad Awais

NAVIGATE


SHARE


How to Use BitBucket and GitHub at the Same Time for One Project?

Ahmad AwaisAhmad Awais

I had a repository for which I needed the remote to be hosted both at BitBucket and GitHub. So, I figured out a few easy solutions to deal with it.

A few EASY solutions.

⚑️ Method #1: Multiple Remotes Pushed (And Fetched) Independently#

This is the easiest to get your head around, but the most effort to maintain.

We start out by adding our new remote:

$ cd myproject
$ git remote add bitbucket ssh://[email protected]/user/myproject.git
$ git push bitbucket master

Straight forward no? Except of course every time we commit any changes, we need to push to both our original β€œorigin” and our new remote β€œbitbucket”:

$ git push origin master
$ git push bitbucket master

Not a massive overhead, but I’m sure it will grate over time. Or you can create an alias alias gpob="git push origin master && git push bitbucket master". That goes in your bash or zsh profile.

⚑️ Method #2: Single Remote With Multiple URLs Pushed (And Fetched) Consecutively#

With this method, we are going to add an additional URL to our existing remote β€œorigin”:

$ cd myproject
$ git remote set-url --add origin ssh://[email protected]/user/myproject.git
$ git push origin master
Everything up-to-date
Everything up-to-date
Much less effort!

Of course silver lining has a cloud, and in this case, it is that while we can push to multiple URLs simultaneously, we can only fetch from the original origin (you can change this, but that is out of scope for this post).

Finally, to see which remote will be fetched from:

$ git remote -v show
Happy hacking!

I help businesses understand developers πŸ“Ÿ Currently recording Node.js CLI Automation Course πŸ‘¨β€πŸ« Edutainer at VSCode.pro 🎩 An award-winning open-source engineer and developer advocate 🦊 Google Developers Expert for web 🌳 Node.js foundation Community Committee member ✌️ Author of various open-source dev-tools and software libraries used by millions of developers worldwide ⓦ WordPress Core Developer πŸ“£ TEDx Speaker πŸ™Œ Leading developers and publishing technical content for over a decade πŸ˜‚ Self-confessed tech comedian cracking silly jokes in the JavaScript web and cloud communities πŸ’œ Loves his wife (Maedah) ❯ Learn more about Awais ↣

Say πŸ‘‹ on Twitter @MrAhmadAwais | Subscribe to the Developers Takeaway!

πŸ“¨

Developers Takeaway

Takeaway my professional opinion on open-source, developer relations, growing your business with family, and everything in between! Delivered to your inbox a couple of times every year. I'm even funny at times. I hate spam β€” pinky-promise!

πŸ‘¨β€πŸ’»πŸ‘©β€πŸ’» 115,834 Developers Already Subscribed