Completely move GIT from one provider to another.
Moving GIT repo around
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
TEMP_REPO_FOLDERNAMEis just a folder name. Any name is ok.
SOURCE_REMOTE_URLis a source (original) git repository url. It can be http or ssh.
NEW_REMOTE_URLis where you want to move your repository to. (must be blank repo).
Let's begin (replace
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