Skip to content

Instantly share code, notes, and snippets.

@haysclark
Created April 21, 2021 19:16
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 haysclark/d0d856949859fe265274adce34d3f9a8 to your computer and use it in GitHub Desktop.
Save haysclark/d0d856949859fe265274adce34d3f9a8 to your computer and use it in GitHub Desktop.
bash script to quickly switch a git repo from master to main
#!/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