Skip to content

Instantly share code, notes, and snippets.

@mandiwise
Last active October 23, 2024 07:20
Show Gist options
  • Save mandiwise/5954bbb2e95c011885ff to your computer and use it in GitHub Desktop.
Save mandiwise/5954bbb2e95c011885ff to your computer and use it in GitHub Desktop.
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
@nenriquez
Copy link

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 [email protected]: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

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

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 [email protected]: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

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

@msyilmaz
Copy link

good solution, it worked for me

@charlesr1971
Copy link

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

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 [email protected]: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

Thanks, worked fine! s2

@abrutsze
Copy link

image
did you get a problem like this?

@codeallthethingz
Copy link

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

@NateAtNTS
Copy link

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 !

@maxoertel
Copy link

Thanks!!

@utilmind
Copy link

utilmind commented Oct 7, 2022

wow, that was easy! thanks for help!

@uzenith360
Copy link

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 this worked!

@sampathdap
Copy link

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 for the tip. it worked for me!

@arifktk32
Copy link

It worked for me, thank you @mandiwise :)

@ufcurmcginty
Copy link

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.

Promote this man! This was my problem :)

@SomervilleTom
Copy link

SomervilleTom commented Feb 22, 2024

According to github importer documenation, the following is NOT imported:

  • Personal repositories owned by users
  • Branch permissions
  • Commit comments
  • Repository settings
  • CI pipelines

This makes the import tool a non-starter for me, my bitbucket repos are all private and I very much want the commit comments.

@SomervilleTom
Copy link

BTW, this thread may see more activity for awhile.. Atlassian in its wisdom has terminated support for Bitbucket Server effective 5-MAR-2024 (2 weeks from now).

@webmaster-lgc
Copy link

+1 for GitHub import tool. It's easier.

Also, in my case, I needed to create an App password in my Bitbucket account settings, and use my Bitbucket username and the created token as credentials when importing. (Read & Write)

Finally, just reset the remote url locally git remote set-url origin [email protected]:username/repo-name.git.

@SomervilleTom
Copy link

SomervilleTom commented Mar 22, 2024

FWIW, Atlassian now tells me that this was a false alarm. Once they figured out how to let me update the expiration date of my credit card, all was fine with my current Bitbucket product. I'm not going to even try to hazard a guess as to its name. The Atlassian site is among the worst I've ever tried to navigate.

@jpgarza93
Copy link

jpgarza93 commented Oct 8, 2024

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.

Give this guy a nobel prize 🙌

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