Skip to content

Instantly share code, notes, and snippets.

@saschazepter
Forked from lietu/hg-git-sync.sh
Created November 9, 2024 23:08
Show Gist options
  • Save saschazepter/40294635640ab28564ee6005fe622312 to your computer and use it in GitHub Desktop.
Save saschazepter/40294635640ab28564ee6005fe622312 to your computer and use it in GitHub Desktop.
Sync a Mercurial (hg) repository to a Git repository
#!/usr/bin/env sh
set -exu
# Which Git repo to sync with - change this for sure
GIT_REPO="git@..."
# Paths
HG_REPO="$(pwd -P)" # You might need to change this
GIT_TMP="/tmp/git-sync-$(date +%s)"
# Ensure SSH key is accepted, you might have to change the grep
REMOTE_HOST=$(echo "${GIT_REPO}" | grep -Eo "git@([^:]+)" | cut -d@ -f2)
if [ "$(ssh-keygen -F ${GIT_REPO})" == "" ]; then
ssh-keyscan -H "${GIT_REPO}" >> ~/.ssh/known_hosts
fi
# Set up temp git folder
mkdir "${GIT_TMP}"
cd "${GIT_TMP}"
git init .
# Sync from HG
git config core.notesRef refs/notes/hg
git remote add origin "hg::${HG_REPO}"
git fetch --all
# Sync to Git
git remote add other "${GIT_REPO}"
git push --all -f other
# Clean up
cd "${HG_REPO}"
rm -rf "${GIT_TMP}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment