Created
April 21, 2020 17:48
-
-
Save woolfg/b4f36b8ba0c351d11712121ea858d771 to your computer and use it in GitHub Desktop.
Script to migrate / move a git repository (incl. tags and branches) to new remote destination
This file contains hidden or 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/bash | |
# | |
# Script migrates git repos incl. branches and tags | |
# from an old remote host to a new one | |
# | |
# Specify one old and new remote destination per line | |
# and separate them with a space | |
repos=( | |
"[email protected]:inlupus_servers/ansible_config.git [email protected]:inlupus/ansible_config.git" | |
); | |
for i in "${repos[@]}"; do | |
from=$(echo $i | cut -d ' ' -f 1) | |
to=$(echo $i | cut -d ' ' -f 2) | |
tmpfolder=$(mktemp -d) | |
echo "Migrating ${from} to ${to}" | |
git clone ${from} ${tmpfolder} | |
cd ${tmpfolder} | |
git fetch -a | |
for branch in $(git branch --all | grep '^\s*remotes' | egrep --invert-match '(:?HEAD|master)$'); do | |
git branch --track "${branch##*/}" "$branch" | |
done | |
git pull --all | |
git remote add new-origin ${to} | |
git push --all new-origin | |
git push --tags new-origin | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment