DEV Community

SaKKo
SaKKo

Posted on

Completely move GIT from one provider to another.

I googled around a lot to see how to move git repository from one remote host to another.

In cloning, my goal is to

  • Make sure that all branches on source remote is cloned
  • Make sure that all tags on source remote is cloned

Then after cloning, my goal is to

  • Push all branches to another remote host
  • Push all tags to another remote host

The way to do this is simple. I've done this with over 20 of my repositories.

  • Bitbucket -> Github
  • Bitbucket -> another bitbucket
  • Github -> Bitbucket
  • Github -> another github
  • Github -> Gitlab
  • Bitbucket -> Gitlab

Let's get started

  • Note:
  • TEMP_REPO_FOLDERNAME is just a folder name. Any name is ok.
  • SOURCE_REMOTE_URL is a source (original) git repository url. It can be http or ssh.
  • example: https://github.com/SaKKo/SKTipAlertView.git
  • NEW_REMOTE_URL is where you want to move your repository to. (must be blank repo).
  • example: https://sakko@bitbucket.org/sakko/SKTipAlertView.git

Let's begin (replace TEMP_REPO_FOLDERNAME SOURCE_REMOTE_URL NEW_REMOTE_URL with what you want then just run the code).

mkdir TEMP_REPO_FOLDERNAME # create a new folder
cd TEMP_REPO_FOLDERNAME
git init --bare .git # create a bare repo
git remote add origin SOURCE_REMOTE_URL # add a remote
git fetch origin refs/heads/*:refs/heads/* # fetch heads
git fetch origin refs/tags/*:refs/tags/* # fetch tags
git init # reinit work tree
git checkout master # checkout a branch
git remote rm origin # remove remote repo
git remote add origin NEW_REMOTE_URL # new remote url
git push -u origin master # now push master
git push --all # now push all other branches

Done!
Hope you find this useful :D

Top comments (0)