Setting Default Branch Name

Learn how to set the default branch name for new Git repositories locally and globally to match your preferred workflow.
Setting Default Branch Name in Git
By default, Git initializes new repositories with the branch named master
. Many teams prefer to use main
or another name as the default branch.
This lesson explains how to configure Git to use your preferred default branch name globally or per repository.
Checking Current Default Branch
New repositories start with the branch named master
by default unless changed.
Set Default Branch Name Globally
To change the default branch name for all new repositories on your machine:
git config --global init.defaultBranch main
Set Default Branch Name Per Repository
Inside an existing repo, override the default for that repo only:
git config init.defaultBranch develop
Initialize a New Repository with Default Branch
After setting this, git init
will create the initial branch with your chosen name.
git init myproject
cd myproject
git branch
This shows the current branch name, matching your default configuration.
Summary
Configuring your default branch name ensures consistency across projects and aligns with modern Git conventions.
Subscribe to Our YouTube for More
https://blog.arashtad.com/updates/setting-default-branch-name/?feed_id=12311&_unique_id=6883b3d1571a3
Comments
Post a Comment