As a developer my default branch is usually develop for my personal projects. (I don’t want to deep dive into details of Git Branching strategies like Trunk-Based Development Git Flow (Feature Based Development) etc. maybe later in another post.)

So I want to make my default branch name other than master for the first commit.

And my common workflow looks like this:

$ git init && git commit --allow-empty -m "Initial commit"
$ git checkout -b develop
$ git push -u origin

So the question is: Is there any another way to change the default first branch name that git init sets?

Solution

Yes, there is, but you need minimum Git version 2.28 (released 2020-07-27). Just run:

$ git config --global init.defaultBranch develop

Or as usual you can add this directly into your global config file:

# ~/.gitconfig
# ~/.config/git/config
# or
# ${XDG_CONFIG_HOME}/git/config

...

[init]
    # >=2.28.0
	defaultBranch = develop

...

Now whenever I initiate a git repo my default branch will be develop and this will save a lot of keystroke.

All done!