DEV Community

Serhat Teker
Serhat Teker

Posted on • Originally published at on

Change Default Git Init Branch

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

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


Yes, there is, but you need minimum Git version 2.28.
Just run:

$ git config --global init.defaultBranch develop
Enter fullscreen mode Exit fullscreen mode

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

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


    # >=2.28.0
    defaultBranch = develop

Enter fullscreen mode Exit fullscreen mode

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

All done!

Top comments (0)