Last active
May 11, 2022 13:45
-
-
Save rajiff/bc6da3f4804eb4795d04bbe1d6dae615 to your computer and use it in GitHub Desktop.
Shell script to migrate a repo from one server to another along with branches & commit history
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 | |
# ensure correct number of arguments are passed | |
if [ "$#" -ne 3 ]; then | |
echo "Usage: $0 <SOURCE Repo URL> <DIR to clone to> <TARGET Repo URL>" >&2 | |
echo "example: /.migrate_git_repo.sh [email protected]:sampleuser/source_repo.git some_folder_name ssh://[email protected]:otheruser/destination_repo.git" | |
return | |
fi | |
srcRepo=$1 | |
cloneToDir=$2 | |
targetRepo=$3 | |
echo "\n\n" | |
echo About migrate $srcRepo to $targetRepo via the folder $cloneToDir | |
# clone to local folder, clone and checkout all branches of the repo | |
git clone --mirror $srcRepo | |
cd ./$cloneToDir.git | |
# fetch everything to local | |
git fetch --tags | |
git fetch -a | |
git tag | |
# this should list all the branches, check none are red (red indicate its not checkedout locally and probably will be missed) | |
git branch -a | |
# move origin from source to target | |
git remote rm origin | |
git remote add origin $targetRepo | |
# push all local repo refs to target | |
git push origin --all | |
git push --tags | |
# clean up the cloned folder | |
#rm -rf ./$cloneToDir | |
# Get back to where the script was triggerred from | |
cd - | |
echo Done migrating $srcRepo to $targetRepo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment