XK0-004 · Question #306
A systems administrator installed Git on a new workstation and wants to ensure all Git projects on this machine are initialized with the same username and email address. Which of the following should
The correct answer is A. git config --global user.name = "James Doe" E. git config --global user.email = "[email protected]". Git global user identity is configured with git config --global user.name and git config --global user.email, which write to ~/.gitconfig and apply to all repositories on the machine.
Question
A systems administrator installed Git on a new workstation and wants to ensure all Git projects on this machine are initialized with the same username and email address. Which of the following should the administrator use to meet this goal? (Choose two.)
Options
- Agit config --global user.name = "James Doe"
- Becho 'email.addr = "[email protected]"' >> .git/.gitconfig
- Cecho 'username' = "James Doe"' >> .git/.gitconfig
- Dgit config username = "James Doe"
- Egit config --global user.email = "[email protected]"
- Fgit config email.addr = [email protected]"
How the community answered
(24 responses)- A96% (23)
- D4% (1)
Why each option
Git global user identity is configured with `git config --global user.name` and `git config --global user.email`, which write to ~/.gitconfig and apply to all repositories on the machine.
The `git config --global user.name` command writes the specified username to the global configuration file at ~/.gitconfig. Because Git reads this file for every repository on the workstation when no local repository-level override exists, this single command ensures consistent author identity across all projects.
This command appends to .git/.gitconfig (a per-repository path that does not exist at the global scope) and uses the invalid key `email.addr` instead of `user.email`, so it neither sets a global value nor uses a recognized Git configuration key.
This command contains a syntax error (mismatched quotes), attempts to write to a per-repository path rather than the global config file, and uses `username` instead of the correct key `user.name`, making it entirely invalid.
Omitting the `--global` flag scopes the setting to the current repository's local .git/config only, and `username` is not a recognized Git configuration key - the correct key is `user.name`.
The `git config --global user.email` command writes the email address to the same ~/.gitconfig file using the correct key `user.email`. Without the `--global` flag the setting would be scoped only to the current repository's .git/config, so the flag is essential for the machine-wide consistency the administrator requires.
This command lacks the `--global` flag so it would only apply locally to the current repository, uses the invalid key `email.addr` instead of `user.email`, and contains a syntax error with a missing opening quotation mark.
Concept tested: Global Git identity configuration with git config
Source: https://git-scm.com/docs/git-config
Topics
Community Discussion
No community discussion yet for this question.