Master No More
Tags: git
Published: 2020-06-15 16:36:34

---
title: Master No More
published: true
date: 2020-06-11 05:00:00 UTC
tags: git
canonical_url: https://waylonwalker.com/blog/master-no-more/
cover_image: https://waylonwalker.com/master-no-more.png
---

Changing master to main is very unlikely to have much affect on the world.  It sure has caused some uproar on the internet lately.  Whether you agree or not, its likely that you will start to see projects migrate away from it. For me it doesn't matter all that much either way, and only really took my like 30 minutes to write this post and make the change.  If you just want to change the branch names it takes no more than 5 minutes.  If you are collaborating on a project, discuss/announce it first.

This is not going to solve any sort of slavery or civil rights issue. 
 If one person happens to notice and feel a bit more welcome to contribute that's great.

---

It's time to do my very small part in this movement and purge master from my active repos starting with this blog right here.

## c-s-f

First off browsing through the content of my blog I found many references to master. I cannot completely whole-sale find and replace each one of them, because some of them are links that I do not own. Any set of instructions got upgraded from `master` to `main`

``` diff
- git checkout master
+ git checkout main
```

There were countless cases of examples like this to comb through, but it feels good to have them purged of old language.

## rename routes

Following yesterdays post, I am going to rename my markdown files

> /static/\_redirects

### shorteners

``` diff
- /gdfm /blog/today-i-learned-git-diff-feature-master/
- /blog/gdfm /blog/today-i-learned-git-diff-feature-master/
+ /gdfm /blog/today-i-learned-git-diff-feature-main/
+ /blog/gdfm /blog/today-i-learned-git-diff-feature-main/
```

### redirect posts

``` diff
+ # master -> main
+ 
+ /blog/today-i-learned-git-diff-feature-master/ /blog/git-diff-feature-main/
```

### redirect external links to repo

``` diff
- /redirects https://github.com/WaylonWalker/waylonwalkerv2/edit/master/static/_redirects
+ /redirects https://github.com/WaylonWalker/waylonwalkerv2/edit/main/static/_redirects
```

More info on refactoring your blog routes with netlify here.

[![gracefully redirect cover image](https://waylonwalker.com/gracefully-redirect.png)](https://dev.to/waylonwalker/refactoring-your-blog-urls-9c)

## _"Edit This post"_ Links

I literally just added _"edit this post"_ links to my rss feed and my blog feed. This was a simple find and replace inside of my blog template and `gatsby-config.js`

## Don't Forget about CI

If you have build/deploy processes that specifically run on master or not on master dont forget to change those to main. I did everything in a single commit and as soon as I pushed to main it started deploying gloriously.

``` diff
name: 🌱 Deploy site

on:
  push:
    branches:
- - master
+ - main
```

## Now the fun part

_removing **master** completely_

I mostly just followed this [post by Scott Hanselman](https://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx).

``` diff
git branch -m master main
git push -u origin main
```

Then from GitHub go to settings>default branch> select main and accept the risk involved.

After your default is set to main, you have no use for master in your life anymore, time to purge it completely once and for all. Go to <repo></repo>/branches and trash it.

![delete master](https://waylonwalker.com/delete-master.png)

## Stop the Bleeding

I like how Scott included this nice alias for starting from main from the beginning.

``` diff
git config --global alias.new '!git init && git symbolic-ref HEAD refs/heads/main'
```

## See the Full Diff

If you happen to want to see the full diff of my change you can see it [here](https://github.com/WaylonWalker/waylonwalkerv2/commit/4bd26ba8faaf7c72e01cc4946d989e3284302cd0).

* * *
  
👀 see an issue, edit this post on [GitHub](https://github.com/WaylonWalker/waylonwalkerv2/edit/main/src/pages/blog/master-no-more.md "edit this post")