Table of contents

How to migrate a Git repository

Git Jul 11, 2020 Viewed 8 Comments 0

Issue

When the ip of the server is changes, or we use a new server. We will have to migrate our git repositories.

Solution

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
Updated Jul 11, 2020