Skip to content

Instantly share code, notes, and snippets.

@sam
Created January 18, 2012 21:40
Show Gist options
  • Save sam/1635893 to your computer and use it in GitHub Desktop.
Save sam/1635893 to your computer and use it in GitHub Desktop.
Script to move repositories to Github.
export LOCAL_GIT_SERVER="[email protected]"
export GITHUB_ACCOUNT="organization"
export GITHUB_USER="username:password"
export REPOS_API="http://github.com/api/v2/json/repos"
function moveit() {
local repository="$1"
if curl -s --user $GITHUB_USER $REPOS_API/show/$GITHUB_ACCOUNT/$repository | grep "error" > /dev/null; then
curl -F "name=$GITHUB_ACCOUNT/$repository" -F "public=0" --user $GITHUB_USER $REPOS_API/create
fi
[ -d /tmp/moveit ] || mkdir /tmp/moveit
pushd /tmp/moveit
echo "Cloning: $repository"
git clone $LOCAL_GIT_SERVER:$repository
pushd $repository
git remote add gh [email protected]:$GITHUB_ACCOUNT/$repository.git
for branch in $(git branch -a | awk '{print $1}' | awk -F'/' '{print $3}'); do
if [ -n "$branch" ] && ! echo "$branch" | grep -E '(HEAD|central)' > /dev/null ; then
echo "PUSHING BRANCH: $branch"
git checkout $branch
git push -u gh $branch
fi
done
for tag in $(git tag -l); do
echo "PUSHING TAG: $tag"
git checkout $tag
git push -u gh $tag
done
echo "ARCHIVING: $repository"
ssh $LOCAL_GIT_SERVER "[ -d archived ] || mkdir archived; mv $repository archived/"
echo 'FIN!'
git branch -a
popd
rm -rf $repository
popd
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment