Skip to content

Instantly share code, notes, and snippets.

@subdavis
Created June 4, 2018 01:53
Show Gist options
  • Save subdavis/5ba04af688cc5716b92f6c409009082b to your computer and use it in GitHub Desktop.
Save subdavis/5ba04af688cc5716b92f6c409009082b to your computer and use it in GitHub Desktop.
Git Mirror to gitlab
gmirror () {
mkdir -p ~/github.com/mirrors
[ -z $1 ] && echo "usage: gmirror new|update" && return;
case $1 in
new)
[ -z $2 ] && echo "usage: gmirror new username oldreponame newreponame" && return;
git clone --mirror [email protected]:$2/$3.git ~/github.com/mirrors/$4.git
pushd .
cd ~/github.com/mirrors/$4.git
git remote set-url --push origin [email protected]:$2/$4.git
popd
gmirror update
;;
update)
pushd .
cd ~/github.com/mirrors
for d in $(ls ~/github.com/mirrors)
do
echo "Updating $d"
cd $d
git fetch -p origin
git push --mirror
cd ..
done
popd
;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment