Last active
August 5, 2020 16:46
-
-
Save mjpitz/a8c62bbd38c15370df79bbd1e6ef7f61 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
# setup credentials for the api | |
export GITHUB_AUTHORIZATION="token PRIVATE-TOKEN" | |
export GITHUB_GROUP="deps-cloud" | |
export BRANCH_NAME="main" | |
# start with a fresh copy of your code (just to be safe) | |
curl -sSL -H "Authorization: ${GITHUB_AUTHORIZATION}" https://api.github.com/users/${GITHUB_GROUP}/repos | \ | |
jq -r .[].ssh_url | \ | |
xargs -I{} git clone {} | |
# checkout a new branch and push it | |
find . -maxdepth 2 -name .git | \ | |
xargs dirname | \ | |
xargs -I{} git --git-dir={}/.git --work-tree={} checkout -b ${BRANCH_NAME} | |
find . -maxdepth 2 -name .git | \ | |
xargs dirname | \ | |
xargs -I{} git --git-dir={}/.git --work-tree={} push -u origin ${BRANCH_NAME} | |
# update the default branch | |
find . -maxdepth 2 -name .git | \ | |
xargs dirname | \ | |
xargs basename -a | \ | |
xargs -I{} echo https://api.github.com/repos/${GITHUB_GROUP}/{} | \ | |
xargs -I{} curl \ | |
-X PATCH \ | |
-H "Content-Type: application/json" \ | |
-H "Authorization: ${GITHUB_AUTHORIZATION}" \ | |
-d "{\"default_branch\": \"${BRANCH_NAME}\"}" {} | |
## | |
## Congratulations! | |
## | |
## You've gotten to the point where active development should no longer be against master. | |
## Now, you don't want to go and delete it quite yet as you might have some external links pointing to the branch. | |
## You'll want to make sure you do an audit of your projects content, badges, and workflows. | |
## Once you've verified all the references have been updated, you'll be able to proceed on. | |
## | |
## Notes: | |
## * Set up a `new` alias for new repository creation: `git config --global alias.new '!git init && git checkout -q -b main'` | |
## * Some system may require making some additional changes (like setting up protected branches). | |
## | |
# delete the master branch | |
find . -maxdepth 2 -name .git | \ | |
xargs dirname | \ | |
xargs -I{} git --git-dir={}/.git --work-tree={} push origin :master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment