brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: init.defaultBranch sets the branch name for every new git repository

Git
~/tips/tip-git-init-default-branch

git config --global init.defaultBranch main

Makes git init start on main, or any name you like, without the hint every time.

A fresh git init without this setting starts on master and prints a hint that the default changes to main in Git 3.0. One line of config picks the name and the hint goes away.

git config --global init.defaultBranch main

From then on, every new repository starts on main. Use whatever name your team uses; git doesn’t care. For a single repository you can also pass it once: git init -b trunk.

I’d set it because most hosting services, GitHub and GitLab included, use main for new repositories. When the local name matches, pushing a new project and setting up tracking needs no renaming.

The setting only affects git init. It doesn’t rename branches in repositories you already have, and git clone ignores it: a clone simply takes whatever default branch the remote has. To rename an existing master to main, use git branch -m master main, then push the new name and change the default branch on the server. Scripts and CI jobs that hard-code the old name need updating too, which is the part I’d check first before renaming anything in a shared project.

Further reading: git-init documentation, git-config documentation

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link