0
0
Gitdevops~10 mins

Default branch name configuration in Git - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Default branch name configuration
Start
Check global config for default branch
Is default branch set?
NoUse 'master' as default
|Yes
Use configured default branch name
Create new repo or init branch
Default branch set
End
This flow shows how Git checks for a configured default branch name and uses it when creating new repositories or branches.
Execution Sample
Git
git config --global init.defaultBranch main
git init myrepo
cd myrepo
git branch
Set default branch to 'main', initialize a repo, and list branches to see the default branch name.
Process Table
StepCommandActionResultNotes
1git config --global init.defaultBranch mainSet global default branch nameConfig updated: init.defaultBranch=mainSets default branch to 'main' for new repos
2git init myrepoInitialize new repoRepository created with default branch 'main'Uses configured default branch name
3cd myrepoChange directoryIn 'myrepo' folderReady to run git commands
4git branchList branchesmainShows default branch is 'main'
5git config --global --unset init.defaultBranchRemove default branch configConfig removedReverts to default 'master'
6cd .. && git init anotherrepo && cd anotherrepoInitialize new repoRepository created with default branch 'master'No config, uses 'master'
7git branchList branchesmasterDefault branch is 'master' now
💡 Execution stops after showing branch names for repos with and without default branch config.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 6Final
init.defaultBranchunsetmainmainunsetunset
current_repo_default_branchnonenonemainmastermaster
Key Moments - 2 Insights
Why does the default branch change from 'master' to 'main' after setting the config?
Because after step 1 sets init.defaultBranch to 'main', git init (step 2) uses this config to create the default branch named 'main' instead of the old default 'master'. See execution_table rows 1 and 2.
What happens if the default branch config is removed?
After removing the config at step 5, git init (step 6) falls back to the default 'master' branch name. This is shown in execution_table rows 5 and 6.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the default branch name after step 2?
Amaster
Bmain
Cdevelop
Dfeature
💡 Hint
Check the 'Result' column in row 2 of the execution_table.
At which step is the default branch config removed?
AStep 3
BStep 6
CStep 5
DStep 7
💡 Hint
Look for the command 'git config --global --unset init.defaultBranch' in the execution_table.
If you set init.defaultBranch to 'develop', what would be the default branch after git init?
Adevelop
Bmaster
Cmain
Dfeature
💡 Hint
The default branch matches the configured name as shown in steps 1 and 2.
Concept Snapshot
git config --global init.defaultBranch <name>
Sets the default branch name for new repositories.
If unset, default is 'master'.
git init uses this config to name the first branch.
Changing this helps align with modern branch naming conventions.
Full Transcript
This visual execution shows how Git uses the init.defaultBranch configuration to set the default branch name when creating new repositories. First, the global config is set to 'main'. Then, initializing a repo creates the 'main' branch instead of 'master'. Removing the config resets the default to 'master'. Listing branches confirms the branch names at each step. This helps beginners see how Git picks the default branch name based on config.