Created
April 21, 2021 19:16
-
-
Save haysclark/d0d856949859fe265274adce34d3f9a8 to your computer and use it in GitHub Desktop.
bash script to quickly switch a git repo from master to main
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
#!/usr/bin/env bash | |
# confirm user action | |
echo "You are about to rename git master branch to main?" | |
read -r -p "Are you sure? [y/N] " response | |
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]] | |
then | |
git branch -m master main | |
git push -u origin main | |
if git push origin --delete master ; then | |
else | |
echo "" | |
echo "Deleting remote master branch failed" | |
hub browse -- settings/branches | |
# wail for user to return | |
read -n 1 -s -r -p "Manually change default branch in GitHub, then Press any key to continue" | |
git push origin --delete master | |
fi | |
echo "Done." | |
exit 0 | |
else | |
echo "Canceled." | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment