Bird
Raised Fist0
Gitdevops~10 mins

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

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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.

Practice

(1/5)
1. What does the init.defaultBranch setting in Git control?
easy
A. The default user name for commits
B. The default remote repository URL
C. The default commit message template
D. The name of the main branch created when initializing a new repository

Solution

  1. Step 1: Understand the purpose of init.defaultBranch

    This setting defines the branch name Git uses when you run git init to create a new repository.
  2. Step 2: Identify what it controls

    It controls the default branch name, usually 'master' or 'main', for new repositories.
  3. Final Answer:

    The name of the main branch created when initializing a new repository -> Option D
  4. Quick Check:

    Default branch name = main branch name [OK]
Hint: Default branch name sets new repo's main branch [OK]
Common Mistakes:
  • Confusing branch name with remote URL
  • Thinking it sets commit message templates
  • Assuming it sets user info
2. Which of the following commands correctly sets the default branch name to main globally in Git?
easy
A. git set defaultBranch main
B. git config --global defaultBranch main
C. git config --global init.defaultBranch main
D. git init --default-branch=main

Solution

  1. Step 1: Recall the correct Git config syntax

    The correct syntax to set a global config is git config --global <key> <value>.
  2. Step 2: Match the key for default branch name

    The key is init.defaultBranch, so the full command is git config --global init.defaultBranch main.
  3. Final Answer:

    git config --global init.defaultBranch main -> Option C
  4. Quick Check:

    Use git config --global init.defaultBranch [OK]
Hint: Use full key: init.defaultBranch with git config [OK]
Common Mistakes:
  • Omitting 'init.' prefix in config key
  • Using 'git set' instead of 'git config'
  • Trying to set default branch during init command
3. After running git config --global init.defaultBranch develop, what will be the default branch name when you run git init in a new folder?
medium
A. master
B. develop
C. main
D. default

Solution

  1. Step 1: Understand the effect of the config command

    Setting init.defaultBranch to 'develop' globally changes the default branch name for all new repos initialized after this.
  2. Step 2: Predict the branch name after git init

    When you run git init, the initial branch will be named 'develop' instead of the usual 'master' or 'main'.
  3. Final Answer:

    develop -> Option B
  4. Quick Check:

    Config set to 'develop' means new repos start with 'develop' [OK]
Hint: New repos use branch name from init.defaultBranch [OK]
Common Mistakes:
  • Assuming default stays 'master' or 'main'
  • Confusing local repo branch with global config
  • Thinking config affects existing repos
4. You tried to set the default branch name with git config --global init.defaultbranch main but new repos still use 'master'. What is the problem?
medium
A. The config key is case-sensitive; it should be init.defaultBranch
B. You need to restart your terminal for changes to apply
C. You must run git init with a special flag to use the new default
D. The default branch name cannot be changed globally

Solution

  1. Step 1: Check the config key spelling

    Git config keys are case-sensitive. The correct key is init.defaultBranch with a capital 'B'.
  2. Step 2: Understand why the setting didn't apply

    Using init.defaultbranch (lowercase 'b') creates a different config entry that Git ignores for default branch naming.
  3. Final Answer:

    The config key is case-sensitive; it should be init.defaultBranch -> Option A
  4. Quick Check:

    Config keys are case-sensitive in Git [OK]
Hint: Check exact case of config keys [OK]
Common Mistakes:
  • Ignoring case sensitivity in config keys
  • Thinking terminal restart is needed
  • Believing default branch can't be changed
5. You want all new repositories on your system to start with the branch name stable. How do you set this globally and verify it?
hard
A. Run git config --global init.defaultBranch stable and then git config --global init.defaultBranch
B. Run git init --default-branch=stable and then git branch
C. Run git config --system init.defaultBranch stable and then git status
D. Run git set defaultBranch stable and then git config --list

Solution

  1. Step 1: Set the global default branch name

    Use git config --global init.defaultBranch stable to set the default branch name for all new repos globally.
  2. Step 2: Verify the setting

    Run git config --global init.defaultBranch to confirm the value is set to 'stable'.
  3. Final Answer:

    Run git config --global init.defaultBranch stable and then git config --global init.defaultBranch -> Option A
  4. Quick Check:

    Set with config, verify with config [OK]
Hint: Set and verify with git config commands [OK]
Common Mistakes:
  • Using incorrect commands like git set
  • Trying to verify with unrelated commands
  • Using system config without permission