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://git@bitbucket.org/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://git@bitbucket.org/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!

Creator of CHAI.new — vibe code ai agents · Founder & CEO of Langbase.com — The most powerful serverless AI agents developer platform to build, deploy, and scale AI agents with tools and memory · Check out the State of AI Agents.

Ex VP DevTools & DevRel Eng. Rapid · Google Developers Advisory Board (gDAB) founding member. 🧑‍💻 AI/ML/DevTools Angel InvestorAI/ML Advisory Board San Francisco, DevNetwork

🎩 Award-winning Open Source Engineer & Dev Advocate 🦊 Google Developers Expert Web DevRel 🚀 NASA Mars Ingenuity Helicopter mission code contributor 🏆 8th GitHub Stars Award recipient with 5x GitHub Stars Award (Listed as GitHub's #1 JavaScript trending developer).

🌳 Node.js foundation Community Committee Outreach Lead, Member Linux Foundation, OpenAPI Business Governing Board, and DigitalOcean Navigator. 📟 Teaching thousands of developers Node.js CLI Automation and VSCode.pro course. Over 142 million views, 24 yrs Blogging, 108K developers learning, 200+ FOSS.

✌️ Author of various open-source dev-tools and software libraries utilized by millions of developers worldwide WordPress Core Developer 📣 TEDx Speaker with 100+ international talks.

✨ As quoted by: Satya Nadella · CEO of Microsoft — Awais is an awesome example for developers.
💜 Loves his wife (Maedah) ❯ Read more about Ahmad Awais.

👋… Awais is mostly active on 𝕏 @MrAhmadAwais

📨

Developers Takeaway

Stay ahead in the web dev community with Ahmad's expert insights on open-source, developer relations, dev-tools, and side-hustles. Insider-email-only-content. Don't miss out - subscirbe for a dose of professional advice and a dash of humor. No spam, pinky-promise!

✨ 172,438 Developers Already Subscribed
View Comments 12