Last active
June 18, 2020 14:19
-
-
Save MatthewEdge/eb04a68860194ed146b9e432498293c4 to your computer and use it in GitHub Desktop.
Migrate Master to Main Alias
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
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!" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doesn't account for WIP!