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 commented Jul 18, 2016

Worked for me thanks!

@haridaniel

This comment has been minimized.

Copy link

haridaniel commented Jul 20, 2016

For me also, thanks! :)

@Vacilando

This comment has been minimized.

Copy link

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 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 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 commented Aug 23, 2016

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

@zockfoul

This comment has been minimized.

Copy link

zockfoul commented Sep 8, 2016

Nice, worked for me, thanks!

@TheOrestes

This comment has been minimized.

Copy link

TheOrestes commented Sep 8, 2016

Awesome! Import Repository tool worked like a charm!

@andrewschultz

This comment has been minimized.

Copy link

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 commented Jan 26, 2017

Thanks!!!

@romenigld

This comment has been minimized.

Copy link

romenigld commented Feb 21, 2017

Thank's!!!

@juniorb2ss

This comment has been minimized.

Copy link

juniorb2ss commented Feb 26, 2017

Thanks!!!

@gabrielmeloarteaga

This comment has been minimized.

Copy link

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 commented Mar 9, 2017

followed original answer and it worked for me thanks.

@rajanhossainkhan

This comment has been minimized.

Copy link

rajanhossainkhan commented Mar 15, 2017

Worked very very well. Thanks a lot.

@achmudas

This comment has been minimized.

Copy link

achmudas commented Mar 25, 2017

Amazing! :)

@orpolaczek

This comment has been minimized.

Copy link

orpolaczek commented Apr 15, 2017

Works like a charm!
Thanks :)

@mrcrowl

This comment has been minimized.

Copy link

mrcrowl commented Apr 21, 2017

Thanks! :) 👍

@xavbeta

This comment has been minimized.

Copy link

xavbeta commented May 18, 2017

Brilliant :)

@tatianagrange

This comment has been minimized.

Copy link

tatianagrange commented Jun 1, 2017

Perfect !
Thanks !

@panatarsoluations

This comment has been minimized.

Copy link

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?

@rahul-sivalenka

This comment has been minimized.

Copy link

rahul-sivalenka commented Jul 15, 2017

Thanks so much for sharing :)

@hopewise

This comment has been minimized.

Copy link

hopewise commented Aug 27, 2017

import tool works great!

@an4s

This comment has been minimized.

Copy link

an4s commented Sep 10, 2017

@trevjones +1 for import tool

@majidpal

This comment has been minimized.

Copy link

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 commented Oct 2, 2017

👍

@brolnickij

This comment has been minimized.

Copy link

brolnickij commented Oct 3, 2017

thanks so much, man!!

@iwan

This comment has been minimized.

Copy link

iwan commented Oct 5, 2017

Thanks

@piksu

This comment has been minimized.

Copy link

piksu commented Oct 9, 2017

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

@senthilsivanath

This comment has been minimized.

Copy link

senthilsivanath commented Oct 18, 2017

Super Simple +1

@Andreiadomz

This comment has been minimized.

Copy link

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 commented Nov 10, 2017

It works! Thanks!

@atularvind

This comment has been minimized.

Copy link

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 commented Nov 28, 2017

Thanks :)

@treddson

This comment has been minimized.

Copy link

treddson commented Dec 15, 2017

savior! thanks

@cesarvega

This comment has been minimized.

Copy link

cesarvega commented Dec 20, 2017

awesome thanks

@SilberMa

This comment has been minimized.

Copy link

SilberMa commented Jan 10, 2018

Thanks a lot! This saved some headache work!

@Viktor19931

This comment has been minimized.

Copy link

Viktor19931 commented Feb 16, 2018

Thank you !!!

@insign

This comment has been minimized.

Copy link

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 commented Mar 13, 2018

Thank you very, very much!

@VivekAgar

This comment has been minimized.

Copy link

VivekAgar commented Mar 25, 2018

Nice, Worked .. thanks

@jpcmf

This comment has been minimized.

Copy link

jpcmf commented Apr 17, 2018

Thank you! :)

@yoshi-ike

This comment has been minimized.

Copy link

yoshi-ike commented May 10, 2018

Thx!!

@arifulhb

This comment has been minimized.

Copy link

arifulhb commented May 25, 2018

Awesome, thanks.

@Blacksuan19

This comment has been minimized.

Copy link

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 commented Jun 6, 2018

Works flawlessly. Thanks.

@kishansinhparmar

This comment has been minimized.

Copy link

kishansinhparmar commented Jun 8, 2018

Great tip!

@thelinuxfaq

This comment has been minimized.

Copy link

thelinuxfaq commented Aug 21, 2018

Its working, Thanks :)

@lydia-gu

This comment has been minimized.

Copy link

lydia-gu commented Aug 29, 2018

It works for GitHub Enterprise as well. Thanks!

@lrajula

This comment has been minimized.

Copy link

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 commented Sep 11, 2018

Awesome, It is much simpler than migration from SVN.

@rajadavidh

This comment has been minimized.

Copy link

rajadavidh commented Sep 27, 2018

Worked for me on Import repository tools. Thanks 👍

@vinitkantrod

This comment has been minimized.

Copy link

vinitkantrod commented Oct 25, 2018

THanks. Worked for me!

@keesvv

This comment has been minimized.

Copy link

keesvv commented Nov 16, 2018

Thank you very much! That fixed a lot! 👍

@oliveratgithub

This comment has been minimized.

Copy link

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 commented Jan 8, 2019

thanks!!!

@avielas

This comment has been minimized.

Copy link

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 commented Mar 14, 2019

What about commit history for migration Bitbucket to Github

@sergofan

This comment has been minimized.

Copy link

sergofan commented Mar 17, 2019

Thanks very merry 😃

@ernestojr

This comment has been minimized.

Copy link

ernestojr commented Mar 18, 2019

+1 for using the import Repository tool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.