A git repository sometimes has to get moved from its existing server to a new one. This can be done with the following steps:

  1. Clone your existing git repository into a temporary directory:
    git clone --mirror <existing-repo-url> /tmp/<temp-directory>
    The argument --mirror makes sure that all branches and tags are cloned.
  2. Change into the temporary clone:
    cd /tmp/<temp-directory>
  3. You may want to check that all branches and tags got cloned indeed; this can be done by
    git tag
    git branch -a
  4. Remove the current remote repository 'origin':
    git remote rm origin
  5. 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).
  6. 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.
  7. Push all branches and tags to the new remote repository:
    git push origin --all
    git push --tags
    
  8. Communicate the URL change, i.e. make sure all other clones of the repository are switched to the new server URL as well.

Sources