Attached is the bitbucket-pipeline. This Bitbucket Pipeline YAML automates the synchronization of Bitbucket public repositories with GitHub, ensuring a 1:1 mirror between both platforms.
Capabilities of the Pipeline:
- Auto-Creates GitHub Repositories – If a repository doesn’t exist on GitHub, it is automatically created.
- Full Repository Mirroring – Uses git push --mirror to sync all branches, tags, commits, and deletions from Bitbucket to GitHub.
- Continuous Updates – Ensures that new commits in Bitbucket are automatically reflected in GitHub.
- Authentication Handling – Securely integrates Bitbucket App Passwords and GitHub PAT Tokens for seamless automation.
- Error Handling & Debugging – Includes logging to track sync issues and authentication failures.
Use Cases Covered:
- One-Time Migration – Easily transfer repositories from Bitbucket to GitHub.
- Ongoing Sync – Ensures repositories in GitHub stay continuously updated with new Bitbucket changes.
- Branch & Tag Management – Keeps all branches and tags identical between platforms.
- Repo Cleanup Enforcement – Automatically deletes branches/tags in GitHub if removed from Bitbucket.
Variables to Add in Bitbucket (Repository Variables) -
These variables should be created under Bitbucket -> Repository Settings -> Repository Variables
BITBUCKET_USERNAME (Bitbucket) Used for API authentication.
BITBUCKET_APP_PASSWORD (Bitbucket) Enables repository access. (Repository: Read, Repository: Write, Account: Read)
BITBUCKET_WORKSPACE (Bitbucket) Identifies the workspace.
GITHUB_USERNAME (GitHub) Used for API authentication.
GITHUB_TOKEN (GitHub) Grants API access for repo creation & pushing.
Link to repository - https://bitbucket.org/pranavbhatia1999/bitbucket-to-github-sync/src/main/
git has a "mirror" option: