Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Transfer repo from Bitbucket to Github
// Reference: http://www.blackdogfoundry.com/blog/moving-repository-from-bitbucket-to-github/
// See also: http://www.paulund.co.uk/change-url-of-git-repository
$ cd $HOME/Code/repo-directory
$ git remote rename origin bitbucket
$ git remote add origin https://github.com/mandiwise/awesome-new-repo.git
$ git push origin master
$ git remote rm bitbucket
@ernestojr
Copy link

ernestojr commented Mar 18, 2019

+1 for using the import Repository tool

@kangaroo02
Copy link

kangaroo02 commented Apr 11, 2019

Thank you very much~

@DBCerigo
Copy link

DBCerigo commented Jul 1, 2019

@dluciano
Copy link

dluciano commented Aug 5, 2019

This is evil 🤣 @bitbucket_

@misterchalm22
Copy link

misterchalm22 commented Aug 20, 2019

Awesome! Import Repository tool worked like a charm!

"Import Repository" worked perfectly for me, too.

@shafikulz
Copy link

shafikulz commented Aug 21, 2019

Thanks, worked perfectly :)

@gjabouley-invn
Copy link

gjabouley-invn commented Sep 24, 2019

Hello
probably worth using a fresh clone with --mirror option, to avoid forgetting something. Also no need for origin/upstream mess.

git clone --mirror ${BITBUCKET_REPO_SSH_URL} ${LOCAL_FOLDER}
git -C ${LOCAL_FOLDER} lfs fetch --all
git -C ${LOCAL_FOLDER} push --mirror ${GITHUB_REPO_SSH_URL}
git -C ${LOCAL_FOLDER} lfs push ${GITHUB_REPO_SSH_URL} --all

Once done, just make a regular clone from Github, and you are all set 😉

@nikdo
Copy link

nikdo commented Oct 24, 2019

Please, don't follow this advice. There are multiple problems with this approach already highlighted by @trevjonez.

The best way to move a repository to GitHub is using GitHub Importer tool. Alternatively it is possible to do it from command line via cloning to bare repository.

Just follow the guidance of GitHub and you'll be fine. 😉

@FaisalZaheer
Copy link

FaisalZaheer commented Mar 10, 2020

👍 @trevjonez - The import tool worked great migrating from Bitbucket.

@brunogfranca
Copy link

brunogfranca commented Apr 19, 2020

I don't know if anyone else needs this, but I created a tool to migrate all repos from a Bitbucket organization account to Github using Github's import tool API.
https://pypi.org/project/bitbucket2github/

@nenriquez
Copy link

nenriquez commented May 7, 2020

Thanks! Works!

@ianpegg
Copy link

ianpegg commented May 29, 2020

This method is only moving the master branch. I would urge you to use the github built in Import Repository tool.
Add repo menu in top right hand corner of most screens

You can then change your local repo to point at the new origin.
git remote -v to print the current settings
git remote set-url origin git@github.com:username/repo-name.git to change origin to the new url (ssh style url shown here, use the https style like above if that is what you prefer.)

then after that you can optionally add the old remote if you have a need.

The problem with doing a remote rename is that any local branches tracking origin will then track bitbucket which may or may not be desirable. Then once you do remote rm the local branches are left with no remote tracking branch, again this may or may not be desirable.

For the purpose of switching from bitbucket to github for which you won't be returning or requiring the ongoing hosting on bitbucket it would be desirable to not rename but simple reassign origin's url with the new github URL.

This is absolutely the right approach. Worked like a charm - cheers!

@faisalahammad
Copy link

faisalahammad commented Jun 18, 2020

I followed this and it's also working fine. How to Move a Private Repository from Bitbucket to Github

@iagorios
Copy link

iagorios commented Sep 12, 2020

👍 importing tool is great option

@ardian27
Copy link

ardian27 commented Oct 30, 2020

great solution, working for me

@entozoon
Copy link

entozoon commented Nov 18, 2020

Same thing but with clone command, and removing $ symbols for copy paste usefulness:

git clone git@bitbucket.org:username/old-repo.git
cd old-repo
git remote rename origin bitbucket
git remote add origin https://github.com/username/new-repo.git
git push origin master
git remote rm bitbucket

@bertho-zero
Copy link

bertho-zero commented Dec 3, 2020

Please prefer SSH to HTTPS if you want to work without entering your credentials for each push.

@msyilmaz
Copy link

msyilmaz commented Dec 19, 2020

good solution, it worked for me

@charlesr1971
Copy link

charlesr1971 commented Feb 7, 2021

This method is only moving the master branch. I would urge you to use the github built in Import Repository tool.

Wow. The GitHub Import Tool is fabulous. I imported a BitBucket repository in a few seconds, without worrying that:

$ git remote rm bitbucket

Might delete my entire BitBucket account...

@field123
Copy link

field123 commented May 7, 2021

+1 for GitHub import tool.

@jstxx
Copy link

jstxx commented May 25, 2021

If you're using bitbucket make sure the login is whatever it says in your https://bitbucket.org/account (not your email address) and generate an app password, that worked for me.

@4sskick
Copy link

4sskick commented Jun 9, 2021

I'm not tried yet, btw what about history commit on repo after moved? will it recorded also or it will just begin from zero?

@4sskick
Copy link

4sskick commented Jul 13, 2021

I'm not tried yet, btw what about history commit on repo after moved? will it recorded also or it will just begin from zero?

already tried & my commit histories followed. Thank you for your snippet commands

@elaine030490
Copy link

elaine030490 commented Sep 30, 2021

This method is only moving the master branch. I would urge you to use the github built in Import Repository tool. Add repo menu in top right hand corner of most screens

You can then change your local repo to point at the new origin. git remote -v to print the current settings git remote set-url origin git@github.com:username/repo-name.git to change origin to the new url (ssh style url shown here, use the https style like above if that is what you prefer.)

then after that you can optionally add the old remote if you have a need.

The problem with doing a remote rename is that any local branches tracking origin will then track bitbucket which may or may not be desirable. Then once you do remote rm the local branches are left with no remote tracking branch, again this may or may not be desirable.

For the purpose of switching from bitbucket to github for which you won't be returning or requiring the ongoing hosting on bitbucket it would be desirable to not rename but simple reassign origin's url with the new github URL.

Thank you so much! This worked perfectly.

@ViniciusDornelasDEV
Copy link

ViniciusDornelasDEV commented Nov 23, 2021

Thanks, worked fine! s2

@abrutsze
Copy link

abrutsze commented Nov 30, 2021

image
did you get a problem like this?

@codeallthethingz
Copy link

codeallthethingz commented Dec 6, 2021

Created a small project to do this - https://github.com/searchspring/bb2gh

@NateAtNTS
Copy link

NateAtNTS commented Jan 12, 2022

awesome! Worked perfectly!

@web-ap
Copy link

web-ap commented Apr 7, 2022

If you're using bitbucket make sure the login is whatever it says in your https://bitbucket.org/account (not your email address) and generate an app password, that worked for me.

Thanks @jstxx it worked for me !

@maximilianoertel-com
Copy link

maximilianoertel-com commented Apr 25, 2022

Thanks!!

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