Renaming your default git branch
Tags: git, tutorial, writing
Published: 2020-01-22 01:06:25

---
title: Renaming your default git branch
published: true
description: Following discourse around harmful technical terms, I decided to rename my default branch on git. Here's how I went about it.
tags: git, tutorial, writing
---

I've seen discourse about technical terminology with harmful origins, specifically the slave/master paradigm. It made me consider the places where I see these terms frequently in my work as a software developer, and one that came to mind is the default branch name in git.

Granted, git branching isn't explicitly defined as a master/slave relationship, but I feel the terms are pervasive enough to warrant avoiding use of either of them. I'm opting to replace my default `master` branch with a `release` branch on all of my non-archived repositories.

### How to rename your default git branch

I used the following steps, as outlined in [this stackoverflow answer](https://stackoverflow.com/a/8762728). These are the commands you'd want to run in your terminal if you're using the command line version of git. I'm not familiar with how this maps to any graphical git tools, but the git operations you'd need to perform would be the same.
```bash
    git checkout -b release master    # create and switch to the release branch
    git push -u origin release        # push the release branch to the remote and track it
    # This is the point where I change the default branch on Github, explained more below.
    git branch -d master              # delete local master
    git push --delete origin master   # delete remote master
    git remote prune origin           # delete the remote tracking branch
```
If you're using a third party site/hosting service, you'll need to follow their steps for renaming the default branch as well. I followed [the steps for doing this on Github](https://help.github.com/en/github/administering-a-repository/setting-the-default-branch). I've included a gif of exactly what this process looked like below.

![Default branch being changed via Github web UI](https://thepracticaldev.s3.amazonaws.com/i/dn3fn24xo28030qhyvjs.gif)

To save a bit of time I did chain the commands like so `git checkout -b release master && git push -u origin release`then went and did the changes on the web user interface and then ran `git branch -d master && git push --delete origin master && git remote prune origin` in my terminal to wrap it all up.

What does it look like to pull down a repository that's had the default branch changed in this way?

I run `git pull` which pullls down the new `release` branch. Then I need to do a bit of local cleanup as follows:
```bash
    #* [new branch]      release    -> origin/release
    # Your configuration specifies to merge with the ref 'refs/heads/master'
    # from the remote, but no such ref was fetched.
    git checkout release
    # Branch 'release' set up to track remote branch 'release' from 'origin'.
    # Switched to a new branch 'release'
    git branch -d master
    # Deleted branch master
    git remote prune origin
    # * [pruned] origin/branch-name 
    # refs/remotes/origin/HEAD has become dangling!
    git remote set-head origin release # so that git knows where the new HEAD is
```
A final note for this procedure is that I didn't have any repositories with open pull requests when I made this change, so unfortunately I cannot say for sure if the base branch for those would also need to get changed over to the new default, I'm assuming so.

### Conclusion

I did this renaming so that my personal work better represents my intent and hopefully contributes towards an easier read for others by eliminating terminology with harmful connotations. I think that it's great to see communities really challenging longstanding terms and trying to do better, and am grateful to have learned something.

As always, thanks for reading!