Migrate old GIT repos to a new remote

After I installed and setup GITOLITE i needed to move my repos from the old remote to the new one.

To do so I created 2 scripts:

  1. Generate the configuration for GITOLITE
  2. Clone the repos and push them to the new remote

Genrating configuration for GITOLITE

I coppied the whole directory structure of GIT repos from the old remote to /path/to/old_repos.

$ git clone ssh://gitolite@SERVER/gitolite-admin.git
$ mkdir migrate
$ cd migrate

In the migrate directory I created configure-gitolite script with following content:

#!/bin/sh

OLD_REPO_PATH=/path/to/old_repos
CONFIG=$1

for repo in `ls ${OLD_REPO_PATH}`; do
	if [ -d ${OLD_REPO_PATH}${repo} ]; then
		name=`echo ${repo} | cut -d. -f1`
		echo -e "repo\t${name}" >> ${CONFIG}
		echo -e "\tRW+\t=\t@developers" >> ${CONFIG}
		echo -e "" >> ${CONFIG}
	fi
done

Then just run in the migrate directory:

$ ./configure-gitolite ../gitolite-admin/conf/gitolite.conf
$ cd ../gitolite-admin
$ git add conf/gitolite.conf
$ git commit -m "Add repos from old remote."
$ git push origin master
$ cd ../migrate

Migrating repos

In the migrate directory I created migrate script with following content:

#!/bin/sh

OLD_REPO_PATH=/path/to/old_repos
NEW_SERVER=$1

for repo in `ls ${OLD_REPO_PATH}`; do
	if [ -d ${OLD_REPO_PATH}${repo} ]; then
		clear
		git clone --mirror ${OLD_REPO_PATH}${repo}
		cd ${repo}
		git remote add new_remote ssh://gitolite@${NEW_SERVER}/${repo}
		git push --mirror new_remote
		cd ..
		rm -rf ${repo}
	fi
done

Just run:

$ ./migrate [NEW_REMOTE_HOST]

Thats it folks!

Leave a Reply

Your email address will not be published. Required fields are marked *