Skip to content

Instantly share code, notes, and snippets.

@cweinberger
Last active June 18, 2020 07:19
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 cweinberger/31e344d3388fea0f03de2a961e010c52 to your computer and use it in GitHub Desktop.
Save cweinberger/31e344d3388fea0f03de2a961e010c52 to your computer and use it in GitHub Desktop.
Change branch from `master` to `main`
# if you are using GitHub, you can use this tool to change all repos at once
# https://github.com/mheap/github-default-branch
# Rename dev to develop
github-default-branch --pat <token> --repo user/repo --old dev --new develop
# Rename all repos owned by an org
github-default-branch --pat <token> --org my-org-name
# Rename all repos owned by a user
github-default-branch --pat <token> --user my-user-name
# create a template file for git
# replace `main` with your new default branch name
echo "ref: refs/heads/main" > ~/.config/git/template/HEAD
# update your git config
# Note: if you already have specified an [init] section, open ~/.gitconfig and add this yourself:
# ~~~
# [init]
# templateDir = ~/.config/git/template"
# ~~~
echo "[init]\n\ttemplateDir = ~/.config/git/template" >> ~/.gitconfig
# test `git init`
# should create a main branch and output: "Reinitialized existing Git repository in {path}/.git/"
git init
# rename `master` branch to `main`
git branch -m master main
# push to origin
git push origin -u main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment