loading...

Renaming your default git branch

skelebrina profile image Sabrina Updated on ・3 min read

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. 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.

    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
Enter fullscreen mode Exit fullscreen mode

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. I've included a gif of exactly what this process looked like below.

Default branch being changed via Github web UI

To save a bit of time I did chain the commands like so git checkout -b release master && git push -u origin releasethen 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:

    #* [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
Enter fullscreen mode Exit fullscreen mode

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!

Discussion

pic
Editor guide
Collapse
innateoptimist profile image
Elizabeth Blackburn 🌹

Thank you for writing this!

Collapse
skelebrina profile image
Sabrina Author

You're very welcome, glad to know it was helpful!