Last active
October 6, 2015 17:58
-
-
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
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
#!/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