Leon Atherton Leon is a developer at IDRsolutions and product manager for BuildVu. He oversees the BuildVu product strategy and roadmap in addition to spending lots of time writing code.

How to git mirror Bitbucket to GitHub with all branches

51 sec read

github screenshot

Recently, I needed to sync a Bitbucket repo to GitHub. I wanted to use a tool that only integrates with GitHub, but our repository lives on Bitbucket!

I found other tutorials that mirrored the repository to GitHub, but they didn’t fully solve my problem because a Bitbucket pipeline only clones a single branch as standard.

Thankfully, setting up an automation to fully mirror a Bitbucket repository to GitHub is very easy to do using a Bitbucket pipeline and GitHub deploy key using these instructions:

  1. On GitHub, create a new repository (import or from scratch).
  2. On Bitbucket, Enable Pipelines under Repository settings > Pipelines > Settings.
  3. On Bitbucket, Generate keys under Repository settings > Pipelines > SSH keys. Copy the public key to clipboard.
  4. On the same page, under Known hosts enter github.com as the Host address and then click Fetch followed by Add host.
  5. On GitHub, add the public key under Settings > Security > Deploy keys > Add deploy key. Tick the checkbox to Allow write access.
  6. On Bitbucket, add the public key under Repository settings > General > Access keys > Add key.
  7. Inside the Bitbucket repo, create a bitbucket-pipelines.yml file containing the following:
    pipelines:
      default:
        - step:
            name: Sync GitHub Mirror
            image: alpine/git:latest
            clone:
              enabled: false
            script:
              - git clone --bare git@bitbucket.org:RepoOrg/RepoName.git
              - cd RepoName.git
              - git push --mirror git@github.com:RepoOrg/RepoName.git

Now, the pipeline automatically mirrors any Bitbucket pushes to GitHub!



Do you need to solve any of these problems?

Display PDF documents in a Web app
Use PDF Forms in a web browser
Convert PDF Documents to an image
Work with PDF Documents in Java

Are you a Developer working with PDF files?

Learn more about PDF file format
Leon Atherton Leon is a developer at IDRsolutions and product manager for BuildVu. He oversees the BuildVu product strategy and roadmap in addition to spending lots of time writing code.

Leave a Reply

Your email address will not be published. Required fields are marked *

IDRsolutions Ltd 2022. All rights reserved.