Skip to content

Instantly share code, notes, and snippets.

@tanhaa
Created October 5, 2019 19:03
Show Gist options
  • Save tanhaa/a3da0c3284e03c948804fa961017fa03 to your computer and use it in GitHub Desktop.
Save tanhaa/a3da0c3284e03c948804fa961017fa03 to your computer and use it in GitHub Desktop.
Moving from bitbucket to github

Moving from bitbucket to github

Note: This procedure can be used to move git repos among any providers, from public github to self-managed github, from bitbucket to github, from github to bitbucket, and so forth and so on.

Procedure for moving (as complete full mirrors)

git clone --bare <bitubucket repo url>

This will not give you a working tree, but ensure all branches, refs, tags are downloaded, this is a bare git repo)

cd repo
# Make a new repo on github and add it as a new remote	
git remote add github <new repo url>
# A mirror push will ensure everything is pushed to the new remote	
git push --mirror github	
cd ..
# Delete the bare repo	
rm -rf repo
# Clone the working tree now	
git clone <new repo url> 	

Ensure the new repo has all the appropriate contributors added to the repo.
Ensure all hooks are properly setup, slack hooks, deploy keys etc on the new repo. If contributor history on the new repo doesn't show someone as a contributor, you may need to attach the public bitbucket email with the github user (ask the contributor to do so if required)

If there are no branches/tags/refs in the original repo, you can simply go the route of adding a new remote, pushing to that remote and removing the origin remote link for bitbucket

Proecure for moving with a new remote

git clone <bitbucket repo url>
git fetch origin
# shows all branches, make sure you have local copies of all branches
git branch -a	
# ensure again that there are local copies, any branch prefixed with remotes/origin/<branchname> without a corresponding 
# local copy needs to be copied over
# Note that if you have to do that, you might as well use the first procedure to move as mirror
git checkout -b <missing branch name> origin/<missing branch name>		
git branch -a	
git remote add github <new github repo url> 		
# push everything to the new github remote
git push --all github
git push --tags github		
# remove the origin bitbucket remote named origin
git remote rm origin
# rename the github remote url as origin
git remote rename github origin

Enjoy your new repo. Make sure no body is pushing to the original bitbucket repo after you have moved, so don't forget to clean up in bitbucket or the original source

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