Move from Github to Bitbucket - Method 2

Move from Github to Bitbucket - Method 2

If you want to move your repository from one hosting service provider to another, check out the method below to do it easily.

To move a repository from GitHub to Bitbucket with all branches and commits, you can follow the steps below:

This one is a detailed method where I am assuming you already have the repository cloned in your local normally. (What do you mean by normally?)

  1. Create a new repository on Bitbucket without README.md and .gitignore.

  1. Switch to the directory of the repository you want to move and check the config file with the following command:
$ cd github-old
$ cat .git/config

You should see something similar to this:

Cannot open the git config file?
The .config folder resides in the repository folder as a hidden directory. You can unhide the file for your OS and enter the folder named .git, inside that you will find a file name config. Just double-click to open with any text editor.
  1. We can see the remote "origin" URL is already present. Now we will add an upstream URL. This upstream URL will be of the new empty Bitbucket repository we just created above.
$ git remote add upstream https://bitbucket.org/USERNAME/REPO-NAME.git

You should see that the upstream is now added to the config file:

  1. Push the main/master branch.

Note: This branch name can vary. For example main, master, prod or whatever.

$ git push upstream main
  1. Push all your other branches to the new repository:

Note: This is the step where all the other branches get created. Otherwise, you would have to switch branches and push each branch. That would have been a pain!!

$ git push upstream refs/remotes/origin/*:refs/heads/*
  1. Push all your tags to the new repository:
$ git push --tags upstream
  1. Now, let's set the new Bitbucket URL as the redirect URL. That is update the origin URL:
$ git remote set-url origin https://bitbucket.org/USERNAME/REPO-NAME.git

Now, check the config file again to confirm the changes:

$ cat .git/config

You should see the updated URLs as below:

  1. Final step: Clone all branches and tags to GitHub Repository
$ git push --mirror

This will push all branches and commits from your local repository to the Bitbucket repository.

Verify that everything was copied correctly. Once the push is complete, navigate to your Bitbucket repository and verify that all of the branches and commits are present.

That's it! Your GitHub repository should now be fully copied over to Bitbucket, with all branches and commits intact.