Skip to content

Instantly share code, notes, and snippets.

@jesselang
Last active October 6, 2015 17:58
Show Gist options
  • Save jesselang/256377c3dc700032087b to your computer and use it in GitHub Desktop.
Save jesselang/256377c3dc700032087b to your computer and use it in GitHub Desktop.
Migrate a git repo from one instance of Altassian Stash/BitBucket to another
#!/bin/sh
# Script to migrate git repos from one instance of Altassian Stash/BitBucket to another.
# Author: Jesse Lang | http://jesselang.com/
REPO=/tmp/migrate-repo-mirror-${USER}
if [ $# -lt 2 ]; then
echo "usage: migrate-repo.sh <current-url> <new-url>"
exit 1
fi
rm -rf ${REPO}
git clone --mirror ${1} ${REPO}
if [ $? -ne 0 ]; then
exit 2
fi
# All pull-request refs must be removed before pushing to stash.
for REF in $(git show-ref |grep refs/pull-requests | cut -d' ' -f2); do
git -C ${REPO} update-ref -d ${REF}
if [ $? -ne 0 ]; then
exit 3
fi
done
git -C ${REPO} remote set-url origin ${2}
git -C ${REPO} push --mirror origin
if [ $? -ne 0 ]; then
exit 4
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment