1

I want to migrate an old Bitbucket repository, containing multiple branches, to Github. To accomplish this, I've followed this description:

# add remote github repository
$ git remote add upstream https://github.com:USER/PROJECT.git
# push all branches <-- doesn't work
$ git push upstream master
$ git push --tags upstream

Only the master branch is pushed to the Github repository (also for git push --all upstream).

In order to push all branches to Github, I need to checkout them individually and do git push upstream.

How can I push all branches to Github without first checkout them?

Shuzheng
  • 9,468
  • 11
  • 67
  • 148

3 Answers3

1

You can do it by using this single command.

git push REMOTE --mirror

You can read more about it here

argo
  • 5,225
  • 4
  • 24
  • 43
1

Follow the below steps.

  1. Mirror the source repo.

    git clone --mirror https://url-of-the-source-git-repo.git

  2. Go to the newly cloned repo

    cd to-your-git-repo-folder.git

  3. set the new remote url.

    git remote set-url --push origin https://url-of-the-destination-git-repo.git

  4. Push to the new repo

    git push --mirror

By following these commands you will migrate to new repo with all the branches and commits.

Chandan Kumar
  • 755
  • 6
  • 15
  • Thank you very much! This seems to be working. Since I'm new to Git, does this make a "hard" copy of the Bitbucket repository on Github, or does it create a "soft" copy, where only references are copied, such that the Github repository references the Bitbucket repository, but doesn't actually contains the files itself? – Shuzheng Nov 12 '19 at 09:50
  • This is going to copy the actual files not the references, you can start working on new repository after migration. – Chandan Kumar Nov 12 '19 at 10:54
0

First make sure that you have fetched all branches.

git fetch --all

Then push all branches to the new remote

git push upstream --all
Tom
  • 3,392
  • 4
  • 22
  • 45
  • It still just push a single branch (`master`). It should be noted that I've never worked on the other branches locally before. It's an old Bitbucket repository that I cloned recently. – Shuzheng Nov 11 '19 at 12:54