Skip to content

Instantly share code, notes, and snippets.

@gnowland
Forked from sangeeths/github-to-bitbucket
Last active July 26, 2025 05:56
Show Gist options
  • Save gnowland/bdefb4e6806f7195c3c10854649f2ada to your computer and use it in GitHub Desktop.
Save gnowland/bdefb4e6806f7195c3c10854649f2ada to your computer and use it in GitHub Desktop.
Forking a Github repo to Bitbucket

Upstream Parity

To facilitate tracking the upstream changes:

  1. Added a git remote called "upstream" which points at the github repo,
  2. Added a local branch called "github/main" to track the "upstream" remote's "main" branch

To pull changes from the upstream project, run:

  git checkout upstream/main
  git pull
  git push origin
  git pull upstream --tags --force
  git push origin --tags --force
  git checkout merge/upstream-main
  git merge main
  git merge upstream/main
  # See "Merge Strategy" instructions below
  # ...resolve merge conflicts...
  git add --all
  git commit --amend --no-edit
  # Create new upstream-## tag
  git tag $(git tag --sort v:refname -l 'upstream-*' | tail -n 1 | awk '{ gsub(/upstream-/, ""); printf "upstream-%02d\n", $1 + 1 }')
  git push
  git push --tags

Merge Strategy

Where conflicts arise, compare OUR changes since last upstream merge to THEIR changes since last upstream merge:

  • Diff of OUR changes since previous merge (replacing upstream-{##} with the previous merge tag number):
    • {bitbucket_url}/compare/diff?sourceBranch=main&targetBranch=tags/upstream-{##}
  • Diff of THEIR changes since previous merge (replacing upstream-{##} with the previous merge tag number):
    • {bitbucket_url}/compare/diff?sourceBranch=tags/nightly&targetBranch=tags/upstream-{##}

NOTE: Always discard lockfile changes. Complete the merge, then see "Package Changes" below for package dependency update strategy.

Package Changes

Ensure updates to the python pyproject.toml and npm package.json packages are appropriately made. Oftentimes OUR updates will incorrectly clobber THEIR updates, resulting in outdated package versions persisting across the upstream merge. Don't let this happen.

  1. Compare THEIR pyproject.toml and package.json diffs to OUR diffs (see above). Whichever has the latest package version shall prevail.
  2. Discard lockfile changes if merge conflicts exist. Update python uv install and npm npm install packages.

Go to Bitbucket and create a new repository (its better to have an empty repo)

git clone [email protected]:abc/myforkedrepo.git
cd myforkedrepo

Now add Github repo as a new remote in Bitbucket called "sync"

git remote add sync [email protected]:def/originalrepo.git

Verify what are the remotes currently being setup for "myforkedrepo". This following command should show "fetch" and "push" for two remotes i.e. "origin" and "sync"

git remote -v

Now do a pull from the "master" branch in the "sync" remote

git pull sync master

Setup a local branch called "github/master" to track the "sync" remote's "master" branch

git branch --track github/master sync/master

Now push the local "master" branch to the "origin" remote in Bitbucket.

git push -u origin master

Courtesy: http://stackoverflow.com/questions/8137997/forking-from-github-to-bitbucket

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment