Logo
BlogDashboardAboutProjects
Logo
HomeBlogDashboardAboutProjects
GithubGithub
LinkedinLinkedin
TwitterTwitter
v1.12.1
26 Feb 2023
·
1 min read

Setting 'main' as your default Git branch

GitHub switched the default branch name from master to main in 2020. One line in your global git config means you never have to set it manually on a new repo again.

All GitHub repositories starts to switch from master to main from 1 October 2020. Despite the change, it is not enforced that the master branch will face with any significant problems if anyone continues to use. However, new repository created will use the main branch as the default.

Since most new projects will now start with the main branch as the default, we would like to reduce the need to re-configure between master and main.

How to use "main" as the default branch

Luckily, git allows us to do this quickly and easily from the global configuration.

There are two ways we can do so.

  1. We can edit the ~/.gitconfig file directly with the following changes.
[init]
	defaultBranch = main
  1. Using the CLI command to set the configuration
git config --global init.defaultBranch main

With the new configuration, we will now be able to create git repositories with the branch being created as main right from the onset.

Of course, certain organisations may use very different naming for their default branch and we can use the same way to make the changes accordingly.

Related Articles

26 Dec 2022
2 tags
Different Git identities for personal and work projects
I kept committing with my personal email on work projects. Git's includeIf directive fixes this by loading a different config based on which directory you're in. No manual switching.
24 Oct 2025
2 tags
How I use GitHub CLI day-to-day
I keep most of my work inside the terminal. Here's how I use gh to create repos, track issues, and merge pull requests without touching the GitHub website.
21 Apr 2026
1 tag
Per-project shell environments with direnv
Loading the right environment variables when I cd into a project used to mean sourcing .env files by hand or leaking secrets into my global shell. direnv fixes both by loading a per-directory shell environment, and unloading it the moment I leave.
13 Sep 2025
1 tag
Patching critical third-party risks you don't control
A critical CVE in an indirect dependency, an inactive upstream, and a release deadline. Here's how I handled it: fork, patch, publish to npm, plan the exit.