Created
September 19, 2014 09:56
-
-
Save mjtorn/3a28dd3220507c3e6ce9 to your computer and use it in GitHub Desktop.
In the event you need to migrate repos from GitHub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Conf section | |
GH_USER=USER | |
DEST_USER=gitolite | |
DEST_HOST=example.com | |
TMPDIR=${HOME}/tmp/gitmigration | |
mkdir -p $TMPDIR | |
set -e | |
test $1 || { | |
echo "Need repository name" | |
exit 1 | |
} | |
REPO=$1 | |
function clone_destination() { | |
echo "clone_destination" | |
cd $TMPDIR | |
git clone ssh://${DEST_USER}@${DEST_HOST}/$REPO | |
} | |
function add_github() { | |
echo "add_github" | |
cd ${TMPDIR}/$REPO | |
git remote add github git+ssh://[email protected]/${GH_USER}/${REPO}.git | |
git fetch github | |
} | |
function migrate_branches() { | |
echo "migrate_branches" | |
cd ${TMPDIR}/$REPO | |
for raw_branch in $(git branch -a); do | |
branch=$(echo $raw_branch | cut -f3 -d/) | |
git checkout -b $branch github/$branch | |
git push -u origin $branch | |
done | |
git push origin --tags | |
} | |
clone_destination $REPO | |
add_github | |
migrate_branches | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment