Skip to content

Instantly share code, notes, and snippets.

@dimkouv
Last active June 3, 2019 08:50
Show Gist options
  • Save dimkouv/8563abb0c1c47eecf9b048177996bf7b to your computer and use it in GitHub Desktop.
Save dimkouv/8563abb0c1c47eecf9b048177996bf7b to your computer and use it in GitHub Desktop.
Mirror a git repository
#!/bin/bash
# Mirror a git repository
# usage: ./gitmirror.sh <copied-repo> <mirror-repo>
#
# example: ./gitmirror.sh https://github.com/dimkouv/app https://gitlab.com/dimkouv/app
if [[ $# -ne 2 ]] ; then
echo 'Invalid arguments!'
exit 1
fi
if [ -d "$1.git" ]; then
echo "ERROR: directory $1.git already exists";
exit 1;
fi
git clone --bare $1.git;
repo=$1
cd ${repo##*/}.git
git push --mirror $2.git;
cd ..;
rm -rf ${repo##*/}.git;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment