Skip to content

Instantly share code, notes, and snippets.

@theothertomelliott
Last active April 29, 2020 16:54
Show Gist options
  • Save theothertomelliott/a49e2ae4c8aa7ca60387b75baf75fa9a to your computer and use it in GitHub Desktop.
Save theothertomelliott/a49e2ae4c8aa7ca60387b75baf75fa9a to your computer and use it in GitHub Desktop.
Migrate a Git repo
#!/bin/sh
# Source and Destination as parameters
SRC=$1
DST=$2
# Clone source repo into a working directory
git clone $SRC working
cd working
# Pull all remote branches and associate with local branches
git fetch --all
for branch in $(git branch --all | grep '^\s*remotes' | egrep --invert-match '(:?HEAD|master)$'); do
git branch --track "${branch##*/}" "$branch"
done
# Push all branches to the destination repo
git remote add dst $DST
git push --all dst
# Clean up
cd ..
rm -rf working
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment