Skip to content

Instantly share code, notes, and snippets.

@waj
Created January 2, 2014 16:21
Show Gist options
  • Save waj/8221708 to your computer and use it in GitHub Desktop.
Save waj/8221708 to your computer and use it in GitHub Desktop.
Migrate mercurial repository to git
#!/bin/bash
function abort() {
echo "ERROR: $1"
echo ""
echo "USAGE: $0 /path/to/new/repo"
exit 1
}
[ $# -eq 1 ] || abort "Invalid parameters count"
[ -d .hg ] || abort "should run this script in an existing mercurial directory"
[ -d $1 ] && abort "$1 should not exist"
TARGET="$1"
GIT="git --git-dir=$TARGET"
BRANCHES=`hg branches | cut -f 1 -d " "`
mkdir -p "$TARGET"
$GIT init --bare
for branch in $BRANCHES; do
hg bookmark -f "git-$branch" -r $branch
done
hg push $TARGET
for branch in $BRANCHES; do
case $branch in
default) new_branch="master" ;;
*) new_branch=$branch
esac
$GIT branch -m "git-$branch" "$new_branch"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment