Created
January 10, 2019 03:12
-
-
Save mattmc3/12a9f7a1e47634674f3c72add4aca761 to your computer and use it in GitHub Desktop.
Bash - migrate git repos
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
gituser=$GIT_USERNAME | |
oldgiturl=bitbucket.org | |
newgiturl=github.com | |
repos=( | |
list | |
your | |
repo | |
names | |
here | |
) | |
addremote() { | |
local new_remote=$1 | |
local cur_remote=`git config --get remote.origin.url` | |
if [[ -z $new_remote ]]; then | |
echo "Expecting new remote argument" 1>&2 && return 1 | |
fi | |
if [[ -z $cur_remote ]]; then | |
echo "Cannot find existing remote URL for repo" 1>&2 && return 1 | |
fi | |
git remote set-url origin --push --add $new_remote | |
git remote set-url origin --push --add $cur_remote | |
} | |
for r in "${repos[@]}" | |
do | |
# [[ -d ./$r ]] && rm -rf ./$r # there be dragons | |
git clone git@${oldgiturl}:${gituser}/${r}.git | |
cd $r | |
addremote git@${newgiturl}:${gituser}/${r}.git | |
git push | |
cd .. | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment