A git repository sometimes has to get moved from its existing server to a new one. This can be done with the following steps:
- Clone your existing git repository into a temporary directory:
git clone --mirror <existing-repo-url> /tmp/<temp-directory>
The argument--mirrormakes sure that all branches and tags are cloned. - Change into the temporary clone:
cd /tmp/<temp-directory>
- You may want to check that all branches and tags got cloned indeed; this can be done by
git tag git branch -a
- Remove the current remote repository 'origin':
git remote rm origin
- On the new server, create a new, empty git repository. Depending on the new server, this might be done in its terminal, or using a web interface (for services as Bitbucket or Github).
- Add this new git repository as a remote repository to your local clone:
git remote add origin <new-repo-url>
where <new-repo-url> is the URL of the new, empty repository created in the step before. - Push all branches and tags to the new remote repository:
git push origin --all git push --tags
- Communicate the URL change, i.e. make sure all other clones of the repository are switched to the new server URL as well.
Sources
-
How to move a full Git repository (article in the Atlassian Blog)