Skip to content

Instantly share code, notes, and snippets.

@mattmc3
Created January 10, 2019 03:12
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 mattmc3/12a9f7a1e47634674f3c72add4aca761 to your computer and use it in GitHub Desktop.
Save mattmc3/12a9f7a1e47634674f3c72add4aca761 to your computer and use it in GitHub Desktop.
Bash - migrate git repos
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