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!

Founder & CEO of ⌘ Command Code coding agent with taste. Founded Langbase.com, AI cloud to build, deploy, and scale AI agents with tools & memory · Creator of Command.new.

"Awais is an awesome example for developers" — Satya Nadella, CEO of Microsoft.

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). Google Developers Expert Web DevRel.

Ex VP Eng (DevTools & DevRel) Rapid · Google Developers Advisory Board (gDAB) founding member · AI/ML/DevTools Angel Investor (Replit, Resend, Daytona, Gumroad and you?) ❯ AI/ML Advisory Board San Francisco, DevNetwork.

Award-winning Open Source Engineering leader authored hundreds of open-source dev-tools and software libraries used by millions of developers, including Shades of Purple code theme and corona-cli.

Linux Foundation (Node.js Committee Lead), OpenAPI Business Governing Board. Taught 108K+ developers via NodeCLI.com and VSCode.pro course. 274 million views, blogging for 24 yrs.

❯ Read more about Ahmad Awais or come say hi on 𝕏 @_AhmadAwais.

📨

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
Comments 12
  • Daniel
    Posted on

    Daniel Daniel

    Reply Author

    Pretty neat trick. Awesome!


  • Muhammad Arslan Aslam
    Posted on

    Muhammad Arslan Aslam Muhammad Arslan Aslam

    Reply Author

    Or the origin can only be on bitbucket and you can use post web hooks on bitbucket to send a custom URL every time a push request is made. That URL can host a file containing instructions to make a pull on your repo on github. Not sure this is a good idea. Would be happy to hear what you think!


    • Ahmad Awais
      Posted on

      Ahmad Awais Ahmad Awais

      Reply Author

      That would contain one too many dependencies, this however is automate-able!


  • Lorenzo
    Posted on

    Lorenzo Lorenzo

    Reply Author

    Pretty cool stuff! Thanks for sharing!


  • Aydın
    Posted on

    Aydın Aydın

    Reply Author

    Hi Ahmad,

    Is it possible to revert it. I’m getting the error below:

    warning: remote.origin.url has multiple values
    fatal: could not set ‘remote.origin.url’ to “…”


    • Aydın
      Posted on

      Aydın Aydın

      Reply Author

      Ok, reverted it in .git/config


  • Abhay
    Posted on

    Abhay Abhay

    Reply Author

    Thanks for the article…do we have to this remote add for all the repos separately or is there a way to do this for all the repos simultaneously? I am trying to clone repos in Bitbucket and gitlab but I have more than 25 repos, so it would be really great if i can do this in all the repos in a single or very few steps instead of adding it individually for all the repos….Thanks!!


  • Abhay
    Posted on

    Abhay Abhay

    Reply Author

    Any way we can do the same changes for all the projects at the same time?


Mentions

  • Abhay
  • Abhay
  • Aydın
  • Aydın
  • Ahmad Awais
  • Lorenzo
  • AhmadAwais
  • Muhammad Arslan Aslam
  • Ahmad Awais
  • Ahmad Awais
  • Muhammad Arslan Aslam
  • Daniel