Skip to content

Instantly share code, notes, and snippets.

@MatthewEdge
Last active June 18, 2020 14:19
Show Gist options
  • Save MatthewEdge/eb04a68860194ed146b9e432498293c4 to your computer and use it in GitHub Desktop.
Save MatthewEdge/eb04a68860194ed146b9e432498293c4 to your computer and use it in GitHub Desktop.
Migrate Master to Main Alias
migrateRepos() {
GIT_BASE="git@github.com:MatthewEdge"
# TODO git base URL
for repo in "$@"; do
echo "Migrating $repo"
git clone "${GIT_BASE}/${repo}.git"
cd "./${repo}"
migrateToMain
cd ../
# Optional cleanup
rm -rf $repo
done
}
migrateToMain() {
CURR_BRANCH=`git symbolic-ref --short HEAD`
TARGET_BRANCH="main"
echo "Migrating master branch to main. Checking out $TARGET_BRANCH when done"
if [ $CURR_BRANCH != "master" ]; then
git stash
STASHED="1"
git checkout master
fi
git branch -m master main
git push -u origin main
git checkout $TARGET_BRANCH
git branch -D master
if [ ! -z "$STASHED" ]; then
git stash pop
fi
echo "Migrated! Make sure to update remote!"
}
@MatthewEdge
Copy link
Author

Doesn't account for WIP!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment