Bird
Raised Fist0
Gitdevops~20 mins

Git configuration (user.name, user.email) - Practice Problems & Coding Challenges

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
Challenge - 5 Problems
🎖️
Git Config Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Check current Git user name configuration
What is the output of the command git config --global user.name if the global user name is set to "Alice Dev"?
Git
git config --global user.name
Anull
Buser.name
Cerror: key does not exist
DAlice Dev
Attempts:
2 left
💡 Hint
This command shows the global user name set in Git configuration.
💻 Command Output
intermediate
1:30remaining
Effect of missing user.email in Git commit
What error message appears if you try to commit in Git but the user.email is not set anywhere in the configuration?
Git
git commit -m "Test commit"
Aerror: user.email is not set
Bfatal: unable to auto-detect email address (got 'username@hostname')
Ccommit created successfully
Dwarning: user.email is empty, using default
Attempts:
2 left
💡 Hint
Git needs an email to identify the author of commits.
Configuration
advanced
2:00remaining
Set local Git user name and email for a repository
Which commands correctly set the local Git user name to "Bob Builder" and email to "bob@build.com" only for the current repository?
A
git config user.name "Bob Builder"
git config user.email "bob@build.com"
B
git config --global user.name "Bob Builder"
git config --global user.email "bob@build.com"
C
git config --local user.name "Bob Builder"
git config --local user.email "bob@build.com"
D
git config --system user.name "Bob Builder"
git config --system user.email "bob@build.com"
Attempts:
2 left
💡 Hint
Local config is the default when no flag is given.
Troubleshoot
advanced
2:00remaining
Diagnose why Git commit uses wrong email
You set your global Git email to "alice@example.com" but commits in a specific repository show author email as "old@example.com". What is the most likely cause?
AGit caches old email and needs restart
BGlobal config is ignored if user.name is missing
CThe repository has a local user.email set to "old@example.com" overriding global config
DThe commit message contains the old email explicitly
Attempts:
2 left
💡 Hint
Local config overrides global config in Git.
Best Practice
expert
2:30remaining
Best practice for managing Git user identity across multiple projects
You work on personal and work projects on the same machine. What is the best way to manage your Git user.name and user.email to keep identities separate?
ASet global user.name and user.email to your personal info, then set local user.name and user.email in work repos to work info
BSet global user.name and user.email to work info, then override locally for personal projects
CUse only global config for all projects and manually change before commits
DSet user.name and user.email only in system config for all projects
Attempts:
2 left
💡 Hint
Global config is default; local config overrides it per repo.

Practice

(1/5)
1. What is the purpose of setting user.name and user.email in Git configuration?
easy
A. To set the default branch name
B. To enable Git debugging mode
C. To configure the remote repository URL
D. To label your commits with your identity

Solution

  1. Step 1: Understand Git commit metadata

    Git uses user.name and user.email to identify who made each commit.
  2. Step 2: Recognize the role of these settings

    These settings label your work so others know who made changes.
  3. Final Answer:

    To label your commits with your identity -> Option D
  4. Quick Check:

    user.name and user.email = commit identity [OK]
Hint: Remember: name and email tag your commits [OK]
Common Mistakes:
  • Confusing user.name with branch name
  • Thinking user.email sets remote URL
  • Assuming these enable debugging
2. Which command correctly sets your global Git user email to "user@example.com"?
easy
A. git config --email user@example.com --global
B. git config --global user.email user@example.com
C. git config user.email --global user@example.com
D. git set user.email global user@example.com

Solution

  1. Step 1: Recall correct Git config syntax

    The correct syntax is git config --global key value.
  2. Step 2: Match the command to set user.email globally

    git config --global user.email user@example.com matches this syntax exactly.
  3. Final Answer:

    git config --global user.email user@example.com -> Option B
  4. Quick Check:

    git config --global key value sets global config [OK]
Hint: Use 'git config --global key value' format [OK]
Common Mistakes:
  • Swapping order of flags and values
  • Using 'git set' instead of 'git config'
  • Placing --global after the key
3. Given these commands run in order:
git config --global user.name "Alice"
git config user.name "Bob"

What will git config user.name output inside the current repository?
medium
A. Bob
B. No output (empty)
C. Alice
D. Error: user.name not set

Solution

  1. Step 1: Understand global vs local config

    The first command sets user.name globally to "Alice". The second sets it locally to "Bob" in the current repo.
  2. Step 2: Determine which config is used

    Local config overrides global inside the repo, so git config user.name shows "Bob".
  3. Final Answer:

    Bob -> Option A
  4. Quick Check:

    Local config overrides global config [OK]
Hint: Local config overrides global config [OK]
Common Mistakes:
  • Assuming global always overrides local
  • Expecting empty output if local set
  • Confusing command order effects
4. You run git config user.email "wrongemail.com" but your commits still show the old email. What is the likely problem?
medium
A. You forgot to add --global or --local, so it set config in an unexpected scope
B. The email format is invalid, so Git ignored the setting
C. You need to restart Git for changes to apply
D. Git does not allow changing user.email once set

Solution

  1. Step 1: Check command scope

    Without --global or --local, Git sets config in the current repo (local) by default.
  2. Step 2: Understand why commits show old email

    If commits show old email, likely you changed config in a different scope than where commits are made.
  3. Final Answer:

    You forgot to add --global or --local, so it set config in an unexpected scope -> Option A
  4. Quick Check:

    Config scope matters; missing flags cause confusion [OK]
Hint: Always specify --global or --local to avoid confusion [OK]
Common Mistakes:
  • Assuming Git ignores invalid emails silently
  • Thinking Git needs restart after config change
  • Believing user.email is immutable
5. You want to set different user names and emails for two projects on the same computer. How do you configure Git correctly?
hard
A. Set user.name and user.email only locally in one project; global config is ignored
B. Set user.name and user.email only globally; Git automatically detects project differences
C. Set global user.name and user.email once, then override locally per project with git config user.name and git config user.email
D. Use environment variables instead of Git config to set user identity

Solution

  1. Step 1: Understand global and local config roles

    Global config applies to all repos unless overridden locally.
  2. Step 2: Apply local overrides per project

    Set local user.name and user.email in each project to customize identity per repo.
  3. Final Answer:

    Set global user.name and user.email once, then override locally per project with git config user.name and git config user.email -> Option C
  4. Quick Check:

    Global sets default; local overrides per project [OK]
Hint: Global sets default; local overrides per project [OK]
Common Mistakes:
  • Expecting Git to auto-detect project identities
  • Setting only local config and ignoring global
  • Using environment variables instead of config