How-To: Rename the Master Branch

It is well past time for your project to get rid of noninclusive terminology in your git branches! Code is for EVERYONE, so in the interest of making our language serve everyone equally, here is instructions for how to do it.

Starting A New Repo

The process is as follows:

  1. Create to your starting directory.
  2. Initialize the repository.
  3. Create a new “main” branch. I prefer main, trunk or root.
  4. Create a new file in the repo. Start with the .gitignore file.
  5. Add that file.
  6. Commit that change.
$ mkdir demo.branchinit
$ cd demo.branchinit
$ git init
Initialized empty Git repository in {Your Directory}

$ git checkout -b "main"
Switched to a new branch 'main'

$ touch .gitignore
$ git add .

$ git commit -am "First commit."
[main (root-commit) {hash}] First commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode {something} .gitignore

$ git branch
* main

Voila! The repo is now rooted off of your main branch, and the word master has nothing to do with it.

Changing an Existing Repo

An existing repo also easy to change, even if you have a remote source setup.

The process follows:

  1. Go to your existing master branch.
  2. Create a new ‘main’ branch, from that master branch.
  3. Drop the master branch.
  4. Push your new main branch to your remote.
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'

$ git checkout -b "main"
Switched to a new branch 'main'

$ git branch -d master
Deleted branch master (was {a hash})

$ git push origin main
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Create a pull request for 'main' on GitHub by visiting:
 * [new branch]      main -> main

Now you just need to reset the default branch in your remote.

  1. Navigate to your remote git source. I use my web browser for this.
  2. Update the default branch to your new ‘main’ branch.
    • In GitHub,
      1. Go to your repo, click Settings
      2. Then Branches on the left.
      3. Select main in the Default Branch box, and click Update.
      4. Then click through the confirmation.
    • In Azure DevOps Services
      1. Go to your repo, then Braches.
      2. Locate the main branch, and then click the 3 dots at the end of the row.
      3. Click ‘Set as default.’

Finally, clean up your local repo’s remote branches.

  1. While still in your main branch, reset the head on your remote.
  2. Delete the master branch!
$ git remote set-head origin -a
origin/HEAD set to main

$ git branch -d master
Deleted branch master (was {a hash})

Alright, you still have some work to do, but your local repo is nice and clean. You’ll still have to clean up your remote, but you can do so just like you would with any other branch delete.

Thanks for doing your part to make everything more inclusive! #blacklivesmatter


This morning, like most of the rest of the US population, I saw protests against police brutality in our cities. Most protests have been nothing but peaceful displays of solidarity. Some, less so, with police responding to property destruction and graffiti with violence, including pepper spraying an eight year old.

I am a pacifist; I do not believe in the use of force, in any case.

Recent news has shown, in clear and not uncertain terms, that being a white male shows that I am not a target. People of color do not enjoy that privilege. It is easy to be a pacifist when systemic racism does not target me.

Statistics back me up here. I am unlikely to be arrested, injured or killed by a police officer. I don’t need to send messages to my friends and family when I have been pulled over by a police officer, as that police officer is unlikely to believe me to be ‘aggressive.’ **

** See the book So You Want to Talk About Race, by Ijeoma Oluo, for details here. Also, it’s just a fascinating book, you should buy it.

In general, I trust police officers to keep us safe. I fully accept that my privileged position supports that trust. That said, I want all people; people of color, LGBTQ people, differently-abled, and any marginalized group I’m (as of yet) unaware of to feel the same.

The police should make people feel safe.

Everyone’s life should matter. However, saying #alllivesmatter’ is fundamentally ignoring systemic racism. Use of force by police statistically impacts people-of-color drastically differently than it impacts white people.

So, being unable to protest myself in the time of COVID19 (I am high risk, heart condition), I will say emphatically here: Black Lives Matter.