Moving a Repository from Bitbucket to GitHub

Some people have asked me how they can move a repository from Bitbucket to Github (or vice versa). To know how to do it we need to understand Git’s remote repositories. Remote repositories are versions of your project that are hosted on the Internet or network somewhere (you can have several of them).

First, let’s clone the Bitbucket repository:

$ git clone
Cloning into ’test'...
remote: Counting objects: 124, done.
remote: Compressing objects: 100% (120/120), done.
remote: Total 124 (delta 42), reused 0 (delta 0)
Receiving objects: 100% (124/124), 1.31 MiB | 541.00 KiB/s, done.
Resolving deltas: 100% (42/42), done.
Checking connectivity... done.

To see which remote servers you have configured, you can run the git remote command. It lists the shortnames of each remote handle you have specified. After cloning your repository you will see origin (that is the default name Git gives to the server you cloned from):

$ cd test
$ git remote

If you use the -v option it will show the URLs that Git has stored for the shortname to be used when reading and writing to that remote:

$ git remote -v
origin (fetch)
origin (push)

Right now origin (our only remote repository) is pointing to Bitbucket, so we could create another remote repository called github and point it to the Github repository we want to move it to. After creating it you could work with both repositories.

Because what we really want is moving it and stop using our original remote repository we should change where origin points to.

We will start renaming origin to bitbucket:

$ git remote rename origin bitbucket

If we want to check it has been renamed we will type:

$ git remote

Then we will add a new remote repository called origin that points to the Github repository we want to move it to:

$ git remote add origin

Now we have two remote repositories (bitbucket and origin):

$ git remote

We can check where they point to:

$ git remote -v
bitbucket (fetch)
bitbucket (push)
origin (fetch)
origin (push)

Then we will push our master branch to the origin remote repository (Github):

$ git push origin master

Once you check the push has been successful you can delete the remote bitbucket repository:

$ git remote rm bitbucket
$ git remote -v
origin (fetch)
origin (push)

You can follow the same process if you want to move a repository from Github to Bitbucket. Just be careful with the repository URLs.



  • On 01.16.16 Saeid Zebardast said:

    Thank you so much. It helps me to move my repositories from BitBucket to GitHub easily.

  • On 03.31.16 David Mortensen said:

    Thank you for this HOWTO. It saved my bacon.

  • On 05.12.16 Andrew Schultz said:

    Thanks for this! I’d been doing it by hand before, but I appreciate the step by step stuff with instructions. Because it helped me make a bit more sense of git, too.

  • On 05.21.16 Andrew Schultz said:

    Thanks for this! It’s clear and helps me with more than just what I wanted to do. In fact, I thought it would only help me once, but I needed it again, and it worked there too.

    I’ll be sharing this with others, and putting the main stuff on my Git cheat sheet.

speak up

Add your comment below, or trackback from your own site.

Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*Required Fields