0
0
Gitdevops~15 mins

Default branch name configuration in Git - Mini Project: Build & Apply

Choose your learning style9 modes available
Default Branch Name Configuration in Git
📖 Scenario: You are working on a new project and want to set the default branch name for all new Git repositories on your computer to main instead of the old default master. This helps keep your projects consistent and modern.
🎯 Goal: Learn how to configure Git to use main as the default branch name for all new repositories you create on your machine.
📋 What You'll Learn
Use the Git command line interface
Set the global Git configuration for default branch name
Verify the configuration change
💡 Why This Matters
🌍 Real World
Many teams and projects now use 'main' as the default branch name to be more inclusive and modern. Setting this globally saves time and keeps your projects consistent.
💼 Career
Knowing how to configure Git defaults is a basic but important skill for developers, DevOps engineers, and anyone working with version control in software projects.
Progress0 / 4 steps
1
Check current default branch name
Run the command git config --global init.defaultBranch to check the current default branch name setting in your global Git configuration.
Git
Need a hint?

This command shows the current default branch name if set. If nothing prints, no default is set yet.

2
Set default branch name to main
Run the command git config --global init.defaultBranch main to set the default branch name to main globally on your computer.
Git
Need a hint?

This command changes the default branch name for all new Git repositories you create.

3
Verify the new default branch name
Run the command git config --global init.defaultBranch again to verify that the default branch name is now set to main.
Git
Need a hint?

The output should now show main as the default branch name.

4
Create a new Git repository to test
Create a new folder called test-repo, navigate into it, and run git init. Then run git branch to see the default branch name of the new repository.
Git
Need a hint?

The output of git branch should show * main indicating the default branch is now main.