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
@alexbooth

This comment has been minimized.

Copy link

@alexbooth alexbooth commented Jul 18, 2016

Worked for me thanks!

@haridaniel

This comment has been minimized.

Copy link

@haridaniel haridaniel commented Jul 20, 2016

For me also, thanks! :)

@Vacilando

This comment has been minimized.

Copy link

@Vacilando Vacilando commented Jul 25, 2016

In my case I had to use the SSH key (git@github.com...) rather than the https URL (which asked for Github name and password).

@trevjonez

This comment has been minimized.

Copy link

@trevjonez trevjonez commented Jul 25, 2016

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.

@morphean

This comment has been minimized.

Copy link

@morphean morphean commented Jul 30, 2016

+1 for using the import Repository tool, it does exactly what it says on the tin.

@mikeclymer

This comment has been minimized.

Copy link

@mikeclymer mikeclymer commented Aug 23, 2016

πŸ‘ @trevjonez - The import tool worked great migrating from Bitbucket.

@zockfoul

This comment has been minimized.

Copy link

@zockfoul zockfoul commented Sep 8, 2016

Nice, worked for me, thanks!

@TheOrestes

This comment has been minimized.

Copy link

@TheOrestes TheOrestes commented Sep 8, 2016

Awesome! Import Repository tool worked like a charm!

@andrewschultz

This comment has been minimized.

Copy link

@andrewschultz andrewschultz commented Sep 11, 2016

This was a great quick reference for me to port over a simple project. Thanks for creating it, and the comment section was well worth reading too.

@sanPuerquitoProgramador

This comment has been minimized.

Copy link

@sanPuerquitoProgramador sanPuerquitoProgramador commented Jan 26, 2017

Thanks!!!

@romenigld

This comment has been minimized.

Copy link

@romenigld romenigld commented Feb 21, 2017

Thank's!!!

@juniorb2ss

This comment has been minimized.

Copy link

@juniorb2ss juniorb2ss commented Feb 26, 2017

Thanks!!!

@gabrielmeloarteaga

This comment has been minimized.

Copy link

@gabrielmeloarteaga gabrielmeloarteaga commented Mar 4, 2017

Thanks @trevjonez and @mandiwise both options worked for me.

But I have a question

If is it possible to fill the contributions timeline too? I mean, I imported the bitbucket repo, but sadly the timeline doesn't filled with the old commits.

Thanks

@waqasraza123

This comment has been minimized.

Copy link

@waqasraza123 waqasraza123 commented Mar 9, 2017

followed original answer and it worked for me thanks.

@rajanhossainkhan

This comment has been minimized.

Copy link

@rajanhossainkhan rajanhossainkhan commented Mar 15, 2017

Worked very very well. Thanks a lot.

@achmudas

This comment has been minimized.

Copy link

@achmudas achmudas commented Mar 25, 2017

Amazing! :)

@orpolaczek

This comment has been minimized.

Copy link

@orpolaczek orpolaczek commented Apr 15, 2017

Works like a charm!
Thanks :)

@mrcrowl

This comment has been minimized.

Copy link

@mrcrowl mrcrowl commented Apr 21, 2017

Thanks! :) πŸ‘

@xavbeta

This comment has been minimized.

Copy link

@xavbeta xavbeta commented May 18, 2017

Brilliant :)

@tatianagrange

This comment has been minimized.

Copy link

@tatianagrange tatianagrange commented Jun 1, 2017

Perfect !
Thanks !

@panatarsoluations

This comment has been minimized.

Copy link

@panatarsoluations panatarsoluations commented Jun 20, 2017

my question is i want to some svn repository some projects is there that all project copy to git hub it means migration it develop java code how?

@rahulsivalenka

This comment has been minimized.

Copy link

@rahulsivalenka rahulsivalenka commented Jul 15, 2017

Thanks so much for sharing :)

@hopewise

This comment has been minimized.

Copy link

@hopewise hopewise commented Aug 27, 2017

import tool works great!

@an4s

This comment has been minimized.

Copy link

@an4s an4s commented Sep 10, 2017

@trevjones +1 for import tool

@majidpal

This comment has been minimized.

Copy link

@majidpal majidpal commented Sep 25, 2017

Ok. So I am new to this. So I have bitbucket private repository and wants to move to Gerrit private repository? Where should i execute above commands? If this are not for me then how we can move private repo?

@torokmark

This comment has been minimized.

Copy link

@torokmark torokmark commented Oct 2, 2017

πŸ‘

@brolnickij

This comment has been minimized.

Copy link

@brolnickij brolnickij commented Oct 3, 2017

thanks so much, man!!

@iwan

This comment has been minimized.

Copy link

@iwan iwan commented Oct 5, 2017

Thanks

@piksu

This comment has been minimized.

Copy link

@piksu piksu commented Oct 9, 2017

@trevjonez +1, the importing tool worked like a charm.

@senthilsivanath

This comment has been minimized.

Copy link

@senthilsivanath senthilsivanath commented Oct 18, 2017

Super Simple +1

@Andreiadomz

This comment has been minimized.

Copy link

@Andreiadomz Andreiadomz commented Nov 4, 2017

super, thanks! sometimes moving around these repos is not easy, thanks for the tip

@et2010

This comment has been minimized.

Copy link

@et2010 et2010 commented Nov 10, 2017

It works! Thanks!

@atularvind

This comment has been minimized.

Copy link

@atularvind atularvind commented Nov 22, 2017

when I transferred my bitbucket repo to my awesome GitHub repo. I need to make a pull before pushing the code. because in new Github repo there where Initial Commit. when I tried to
git pull origin master
It says.

fatal: refusing to merge unrelated histories

As a solution, I pulled branch with --allow-unrelated-histories option.
git pull origin master --allow-unrelated-histories
After that, the push worked!
Hope this helps!

@ranka47

This comment has been minimized.

Copy link

@ranka47 ranka47 commented Nov 28, 2017

Thanks :)

@treddson

This comment has been minimized.

Copy link

@treddson treddson commented Dec 15, 2017

savior! thanks

@cesarvega

This comment has been minimized.

Copy link

@cesarvega cesarvega commented Dec 20, 2017

awesome thanks

@SilberMa

This comment has been minimized.

Copy link

@SilberMa SilberMa commented Jan 10, 2018

Thanks a lot! This saved some headache work!

@Viktor19931

This comment has been minimized.

Copy link

@Viktor19931 Viktor19931 commented Feb 16, 2018

Thank you !!!

@insign

This comment has been minimized.

Copy link

@insign insign commented Feb 19, 2018

Github currently has a import tool, fast and simple. Just create the repo, then choose to import from another repo.

@ntraykov

This comment has been minimized.

Copy link

@ntraykov ntraykov commented Mar 13, 2018

Thank you very, very much!

@VivekAgar

This comment has been minimized.

Copy link

@VivekAgar VivekAgar commented Mar 25, 2018

Nice, Worked .. thanks

@jpcmf

This comment has been minimized.

Copy link

@jpcmf jpcmf commented Apr 17, 2018

Thank you! :)

@yoshi-ike

This comment has been minimized.

Copy link

@yoshi-ike yoshi-ike commented May 10, 2018

Thx!!

@arifulhb

This comment has been minimized.

Copy link

@arifulhb arifulhb commented May 25, 2018

Awesome, thanks.

@Blacksuan19

This comment has been minimized.

Copy link

@Blacksuan19 Blacksuan19 commented May 26, 2018

btw you can also use this to track multiple remotes
for example each remote with a different name other than original and you can just fetch merge and do all operations on it

@vgashic

This comment has been minimized.

Copy link

@vgashic vgashic commented Jun 6, 2018

Works flawlessly. Thanks.

@kishansinhparmar

This comment has been minimized.

Copy link

@kishansinhparmar kishansinhparmar commented Jun 8, 2018

Great tip!

@thelinuxfaq

This comment has been minimized.

Copy link

@thelinuxfaq thelinuxfaq commented Aug 21, 2018

Its working, Thanks :)

@lydia-gu

This comment has been minimized.

Copy link

@lydia-gu lydia-gu commented Aug 29, 2018

It works for GitHub Enterprise as well. Thanks!

@lrajula

This comment has been minimized.

Copy link

@lrajula lrajula commented Sep 7, 2018

Hi,
I would like to move repositories from Bit bucket to github.Is there any restapi call for that, so that I can write python script then move repositories from Bit bucket to Github.Please suggest.

@youth6erry

This comment has been minimized.

Copy link

@youth6erry youth6erry commented Sep 11, 2018

Awesome, It is much simpler than migration from SVN.

@rajadavidh

This comment has been minimized.

Copy link

@rajadavidh rajadavidh commented Sep 27, 2018

Worked for me on Import repository tools. Thanks πŸ‘

@vinitkantrod

This comment has been minimized.

Copy link

@vinitkantrod vinitkantrod commented Oct 25, 2018

THanks. Worked for me!

@keesvv

This comment has been minimized.

Copy link

@keesvv keesvv commented Nov 16, 2018

Thank you very much! That fixed a lot! πŸ‘

@oliveratgithub

This comment has been minimized.

Copy link

@oliveratgithub oliveratgithub commented Dec 10, 2018

I used a newer tutorial – making use of "upstream" and not "origin"; which seems to not do something like a fork, but chaning the real origin of the Repo:

$ cd PROJECT
$ git remote add upstream https://github.com/zorgch/zorg-code.git
$ git push upstream master
$ git push --tags upstream

Source: https://medium.com/@RobertKhou/how-to-migrate-from-bitbucket-to-github-75c87a892767

@fjorquerauribe

This comment has been minimized.

Copy link

@fjorquerauribe fjorquerauribe commented Jan 8, 2019

thanks!!!

@avielas

This comment has been minimized.

Copy link

@avielas avielas commented Jan 9, 2019

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.

thanks!

@ashokvaddevalli

This comment has been minimized.

Copy link

@ashokvaddevalli ashokvaddevalli commented Mar 14, 2019

What about commit history for migration Bitbucket to Github

@sergofan

This comment has been minimized.

Copy link

@sergofan sergofan commented Mar 17, 2019

Thanks very merry πŸ˜ƒ

@ernestojr

This comment has been minimized.

Copy link

@ernestojr ernestojr commented Mar 18, 2019

+1 for using the import Repository tool

@kangaroo02

This comment has been minimized.

Copy link

@kangaroo02 kangaroo02 commented Apr 11, 2019

Thank you very much~

@DBCerigo

This comment has been minimized.

Copy link

@DBCerigo DBCerigo commented Jul 1, 2019

@dluciano

This comment has been minimized.

Copy link

@dluciano dluciano commented Aug 5, 2019

This is evil 🀣 @bitbucket_

@misterchalm22

This comment has been minimized.

Copy link

@misterchalm22 misterchalm22 commented Aug 20, 2019

Awesome! Import Repository tool worked like a charm!

"Import Repository" worked perfectly for me, too.

@shafikulz

This comment has been minimized.

Copy link

@shafikulz shafikulz commented Aug 21, 2019

Thanks, worked perfectly :)

@gjabouley-invn

This comment has been minimized.

Copy link

@gjabouley-invn 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

This comment has been minimized.

Copy link

@nikdo 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

This comment has been minimized.

Copy link

@FaisalZaheer FaisalZaheer commented Mar 10, 2020

πŸ‘ @trevjonez - The import tool worked great migrating from Bitbucket.

@brunogfranca

This comment has been minimized.

Copy link

@brunogfranca 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

This comment has been minimized.

Copy link

@nenriquez nenriquez commented May 7, 2020

Thanks! Works!

@ianpegg

This comment has been minimized.

Copy link

@ianpegg 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

This comment has been minimized.

Copy link

@faisalahammad 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

This comment has been minimized.

Copy link

@iagorios iagorios commented Sep 12, 2020

πŸ‘ importing tool is great option

@ardian27

This comment has been minimized.

Copy link

@ardian27 ardian27 commented Oct 30, 2020

great solution, working for me

@entozoon

This comment has been minimized.

Copy link

@entozoon 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

This comment has been minimized.

Copy link

@bertho-zero bertho-zero commented Dec 3, 2020

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

@msyilmaz

This comment has been minimized.

Copy link

@msyilmaz msyilmaz commented Dec 19, 2020

good solution, it worked for me

@charlesr1971

This comment has been minimized.

Copy link

@charlesr1971 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

This comment has been minimized.

Copy link

@field123 field123 commented May 7, 2021

+1 for GitHub import tool.

@jstxx

This comment has been minimized.

Copy link

@jstxx 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

This comment has been minimized.

Copy link

@4sskick 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

This comment has been minimized.

Copy link

@4sskick 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

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