How to migrate a Git repository
When the ip of the server is changes, or we use a new server. We will have to migrate our git repositories.
There are two ways to migrate our git repositories.
1. Copy all files of the server over
All the information (orgin, trunk, etc.) about the repository are stored in a folder named '.git', where we are initializing the repository. So, we need to copy the contents to the new server with the
scp command. It's really that simple.
scp REPOSITORY.git ssh://USERNAME@new.github.com/REPOSITORY.git
Finally change the git remote's URL on the client side.
git remote set-url origin ssh://USERNAME@new.github.com/REPOSITORY.git
2. With push command
We can also init a new repository on the new server.
git init --bare --shared REPOSITORY.git
And push the code on the client side.
# change remote url git remote set-url origin ssh://USERNAME@new.github.com/REPOSITORY.git # push all the branches to the server git push --all