2

Using git through wsl (ubuntu) & windows terminal, how do you change the default branch name to main?

I've already tried:

git config --global init.defaultBranch main

and the setting "init.defaultbranch=main" is there when I look at:

git config --global --list

but when I try to make a new git init in a brand new folder it still uses master... Any ideas?

  • 1
    As you saw, Git versions before 2.28 simply don't have this as an option (they ignore any `init.defaultBranch` setting). Note, though, that you can simply run `git checkout -b main` after `git init` creates the empty repository, including in both the old and new Git versions. – torek May 15 '21 at 22:24

1 Answers1

4

So it turns out you need git version 2.28 or higher. I had git version 2.25.1 even though I just installed git a few months ago. For Ubuntu it seems you have to jump through a few hoops to get the lastest version.

This is what I tried

sudo apt-add-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git

After that you can check your version using:

git --version

If you added the global setting in the code from my question you should be good to go.

  • This answer still works as of 2023-04-21. I installed Ubuntu 18.04 in WSL2 (my remote web host uses this version and I am emulating its environment on my local), and that has git 2.17.1. This answer got me to 2.40.0 – Fred Polli Apr 21 '23 at 12:59