Last active
April 29, 2020 16:54
-
-
Save theothertomelliott/a49e2ae4c8aa7ca60387b75baf75fa9a to your computer and use it in GitHub Desktop.
Migrate a Git repo
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/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