'git init -b <branch name>' command in terminal is throwing an 'unknown switch' error
The -b
flag is only available in version 2.28 or later, you need to upgrade your Git.
On debian-based Linux systems such as Ubuntu, do the following:
sudo add-apt-repository -y ppa:git-core/ppasudo apt updatesudo apt install git -y
prior to git v2.28
git init # ①git symbolic-ref HEAD refs/heads/main # ②
① After git init
, the branch master
does not actually exist. Branches get created only when they have at least one commit.
② This updates .git/HEAD
to contain ref: refs/heads/main
instead of ref: refs/heads/master
. Alternatively, git checkout -b main
.
git v2.28+
As @phd said, the -b/--initial-branch
option was added in git v2.28. git 2.28 also introduces a config option to specify your preferred default branch:
git config --global init.defaultBranch main
Learn more about the new init.defaultBranch
setting in GitHub's blog post.