Last active
August 11, 2020 19:07
-
-
Save escowles/eed4567d818f77811311386df8e71133 to your computer and use it in GitHub Desktop.
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
#!/bin/sh | |
# usage: | |
# $ export GITHUB_TOKEN=[token] | |
# $ rename-master-to-main.sh [org] [repo] | |
# generate GITHUB_TOKEN at https://github.com/settings/tokens/new with "repo" privileges | |
ORG="$1" | |
REPO="$2" | |
rm -rf $REPO | |
git clone [email protected]:$ORG/$REPO.git | |
cd $REPO | |
# 1. make sure master exists and main does not # XXX fail if not true | |
MASTER=`git branch --list master` | |
MAIN=`git branch --list main` | |
if [ -z "$MASTER" ]; then | |
echo "The 'master' branch does not exist, exiting" | |
exit 1 | |
fi | |
if [ ! -z "$MAIN" ]; then | |
echo "The 'main' branch already exists, exiting" | |
exit 1 | |
fi | |
git switch master | |
git pull | |
if [ $? -gt 0 ]; then | |
echo "Problems pulling changes from 'master' branch, exiting" | |
exit 1 | |
fi | |
git branch -m master main | |
git symbolic-ref --short refs/heads/master refs/heads/main | |
git push origin main | |
if [ $? -gt 0 ]; then | |
echo "Problems pushing changes to 'main' branch, exiting" | |
exit 1 | |
fi | |
JSON="{\"name\":\"$REPO\", \"default_branch\":\"main\"}" | |
TOKEN="token $GITHUB_TOKEN" | |
curl -X PATCH -H "Content-Type: application/json" -H "Authorization: $TOKEN" -d "$JSON" https://api.github.com/repos/$ORG/$REPO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment