-2

On vscode, using wsl terminal, I was setting the global the default branch as main as shown below,

git config --global init.defaultBranch main

Now, inside my project folder, when I do git init and check git status the default branch is still master. What else I need to do to make the default branch as main?

Even .gitconfig, contains defaultBranch as main:

cat ~/.gitconfig

[init]
    defaultBranch = main

Current git version:

git version2.25.1
Python coder
  • 743
  • 5
  • 18

2 Answers2

1

Git has multiple levels of config: system, global, local.

If you want to quickly verify what happens in your local repo justgit config -e --local or git config --list to see

Otherwise modify the global ~/.gitconfig yourself config and add/update section:

[init]
  defaultBranch = main
dejanualex
  • 3,872
  • 6
  • 22
  • 37
  • `git config --list` this show `defaultBranch = main`, but still when I do `git init`, I see `master` branch as default :| – Python coder Aug 07 '23 at 11:17
-2

I tried to update the git version from git version2.25.1 to current latest version i.e., git version 2.41.0. After this my git configurations are getting correctly detected.

From @RickN's comment,

The defaultBranch option was introduced in Git 2.28, so your config file was detected without fault, just with an unsupported configuration option.

Python coder
  • 743
  • 5
  • 18
  • 1
    The `defaultBranch` option was introduced in Git 2.28, so your config file was detected without fault, just with an unsupported configuration option. – RickN Aug 07 '23 at 11:28
  • Now got to know the exact reason. Thanks for clarifying. You can post this as answer, I will accept :) – Python coder Aug 07 '23 at 11:29
  • Nah, its fine, you solved it yourself so just edit that in & self-accept your own answer (may take a little while until it gives you the option). – RickN Aug 07 '23 at 11:34