Last active
June 15, 2020 20:48
-
-
Save konrad/0ad0358cc3e0a2d6427e92fcd9b6e72e to your computer and use it in GitHub Desktop.
Script to mass rename the master branch to main branch in git repos.
This file contains hidden or 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
#!/bin/env bash | |
# | |
# Copyright 2020 Konrad Förstner | |
# | |
# Permission to use, copy, modify, and/or distribute this software for | |
# any purpose with or without fee is hereby granted, provided that the | |
# above copyright notice and this permission notice appear in all | |
# copies. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL | |
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED | |
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE | |
# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | |
# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | |
# PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | |
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | |
# PERFORMANCE OF THIS SOFTWARE.b | |
# Inspired by https://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx | |
# Adapt if needed | |
ROOT_FOLDER=~/ | |
echo "This script will rename local and remote git branches from 'master' to 'main'!" | |
echo "Use at your own risk!" | |
for FOLDER in $(find ${ROOT_FOLDER} -name ".git" | sed "s/.git$//") | |
do | |
echo ${FOLDER} | |
read -p "Rename master to main? " yn | |
case $yn in | |
[Yy]* ) cd ${FOLDER} && git branch -m master main && git push -u origin main && git push origin --delete master;; | |
[Nn]* ) echo Skipped repo; continue;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
echo "" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment