GitHub to Bitbucket Mirroring (With Commit History & Sync).
Requirement.
In some environments, projects are actively developed and deployed using GitHub, but there is also a need to maintain a synchronized copy in Bitbucket.
The goal is to:
Mirror the repository from GitHub to Bitbucket
Preserve full commit history
Keep both repositories in sync for continuous deployment
Step-by-Step Implementation.
Clone the GitHub Repository.
$ git clone git@github.com:<github_user_name>/<github_repo_name>.git
cd <github_repo_name>
Rename Default Remote.
$ git remote rename origin github
Add Bitbucket as a Remote.
$ git remote add bit <bitbucket_repo_url>
Fetch Bitbucket Data.
Checkout Bitbucket Branch.
$ git checkout -b bit-branch bit/<branch_name>
Merge GitHub into Bitbucket.
If both repositories were created independently, Git may treat them as unrelated histories.
Resolve any merge conflicts if prompted.
$ git merge github/<branch_name> --allow-unrelated-histories
Push to Bitbucket.
$ git push bit <branch_name>
Keeping Repositories in Sync.
$ git pull github <branch_name>
git push bit <branch_name>