Skip to content

Instantly share code, notes, and snippets.

@blobaugh
Created October 30, 2018 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blobaugh/e7bf132f0bf01ebc9e48bdec728031fa to your computer and use it in GitHub Desktop.
Save blobaugh/e7bf132f0bf01ebc9e48bdec728031fa to your computer and use it in GitHub Desktop.
Migrate one git repo to another
# 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