DEV Community

Abubakkar Sithik
Abubakkar Sithik

Posted on

Automating Mirroring Between Bitbucket and GitHub

💡 The primary objective of this process is to demonstrate the feasibility and functionality of setting up automated mirroring between Bitbucket and GitHub repositories.


This article outlines the steps to mirror a Bitbucket repository to a GitHub repository. The process involves configuring Bitbucket Pipelines to automate the synchronization of code changes between the two repositories. This setup can be particularly useful for teams looking to leverage GitHub’s enhanced collaboration features and seamless integration with existing toolsets while still maintaining their existing Bitbucket repositories.

Steps to Automate Mirroring

The following steps will guide you through establishing automated mirroring from Bitbucket to GitHub:

1. GitHub Repository Setup

  • Create a new repository on GitHub. For this example, we'll refer to it as "github-repo".

2. Bitbucket Pipelines Configuration

  • Enable Pipelines under Repository settings > Pipelines > Settings on Bitbucket.

    Enable Pipelines

3. SSH Key Generation (Bitbucket)

  • Generate SSH keys under Repository settings > Pipelines > SSH keys on Bitbucket.
  • Copy the public key to the clipboard.

    Generate SSH Keys

4. Known Hosts Configuration (Bitbucket)

  • Add as the Host address under Known hosts.
  • Click Fetch followed by Add host.

    Configure Known Hosts

5. Deploy Key Configuration (GitHub)

  • Add the public key under Settings > Security > Deploy keys > Add deploy key on GitHub.
  • Enable write access for the deploy key.

    Add Deploy Key

6. Access Key Configuration (Bitbucket)

  • Add the public key under Repository settings > Security > Access keys > Add key on Bitbucket.

    Add Access Key

7. Pipeline Configuration (Bitbucket)

  • Create a bitbucket-pipelines.yml file inside the Bitbucket repository with the following content:

    image: atlassian/default-image:3
      # Automated pipeline for syncing Bitbucket repository with its GitHub mirror, ensuring real-time updates across platforms
          - step:
              name: Sync GitHub Mirror
              image: alpine/git:latest
                enabled: false
                - git clone --bare
                - cd bitbucket-repo.git
                - git push --mirror

This configuration ensures that any code push to the Bitbucket repository will initiate a Bitbucket pipeline job, triggering automatic mirroring to the GitHub repository. The synchronization of code changes prepares the team for a seamless transition to using GitHub as their primary repository platform.


By following these steps, you can automate the mirroring of a Bitbucket repository to a GitHub repository. This setup ensures that any code push to the Bitbucket repository triggers an automatic pipeline job, mirroring the changes to the GitHub repository. This process is beneficial for teams looking to utilize GitHub’s advanced features while maintaining their existing workflows on Bitbucket.

Note: Further optimization and fine-tuning may be required for production deployment.

Top comments (0)