Created
October 30, 2018 17:32
-
-
Save blobaugh/e7bf132f0bf01ebc9e48bdec728031fa to your computer and use it in GitHub Desktop.
Migrate one git repo to another
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
# Migrate a repository from one git source to another | |
# Usage: gitmigrate <first_repo_url> <new_repo_url> | |
gitmigrate() { | |
oldrepo=$1 | |
newrepo=$2 | |
echo Migrating from $oldrepo to $newrepo | |
# Pull down the repository | |
git clone $oldrepo repo | |
cd repo | |
# Snag all the branches in the repo | |
for branch in $(git branch --all | grep '^\s*remotes' | egrep --invert-match '(:?HEAD|master)$'); do | |
git branch --track "${branch##*/}" "$branch" | |
done | |
# Get all the tags | |
git fetch --tags | |
# Add the remote repo | |
git remote add gh $newrepo | |
# Push all the branches and tags to the new repo | |
git push gh --all | |
git push gh --tags | |
# Clean up | |
cd .. | |
rm -rf repo | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment