Skip to content

Instantly share code, notes, and snippets.

@fabn
Created June 6, 2013 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabn/5720707 to your computer and use it in GitHub Desktop.
Save fabn/5720707 to your computer and use it in GitHub Desktop.
I've used this script to synchronize two gitolite installation after permissions has been set in the new repository. Needs password less ssh or ssh agent to work. Can be executed multiple times.
#!/bin/sh
[ $DEBUG ] && set -x
WORKDIR=/tmp/repos
OLD_HOST=git.example.org
OLD_USER=gitolite
NEW_HOST=git.example.com
NEW_USER=gitolite
REPOS='comma,separated,list,of,repositories'
IFS=','
[ -d $WORKDIR ] || mkdir -p $WORKDIR
cd $WORKDIR
for repo in $REPOS; do
echo "Migrating '$repo' to new host $NEW_HOST"
# Clone a full copy of existing repository
[ -d $repo.git ] || git clone --mirror $OLD_USER@$OLD_HOST:$repo
cd $repo.git
# This is used if script is invoked multiple times to fetch new updates
git fetch -q --all
# Add new origin if not present
git remote | grep new_origin > /dev/null || git remote add new_origin $NEW_USER@$NEW_HOST:$repo
# Push everything to new location, doesn't handle forced push in old repository (which is bad)
git push --all new_origin
git push --tags new_origin
cd $WORKDIR
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment