Git Git Configuration and Setup 1 β Questions and Answers
Question 1: Which command sets your global Git username?
- git config user.name 'Name'
- git config --global user.name 'Name' (Correct answer)
- git setup --name 'Name'
- git init --user 'Name'
Correct answer: git config --global user.name 'Name'
The `git config --global user.name 'Name'` command sets the author name for all commits across all repositories on the system.
Question 2: Where does Git look for configuration in order of precedence from highest to lowest?
- System β Global β Local
- Local β Global β System (Correct answer)
- Global β System β Local
- Local β System β Global
Correct answer: Local β Global β System
Git applies configuration in order: local (`.git/config`) overrides global (`~/.gitconfig`) which overrides system (`/etc/gitconfig`).
Question 3: Which command displays all active Git configuration values and their sources?
- git config --all
- git config --list --show-origin (Correct answer)
- git config -v
- git config --dump
Correct answer: git config --list --show-origin
The `git config --list --show-origin` command lists every configuration setting currently in effect along with the file path where each setting comes from.
Question 4: How do you configure the default text editor for Git commit messages?
- git config --global core.editor 'vim' (Correct answer)
- git config --global editor 'vim'
- git config --global commit.editor 'vim'
- git setup --editor 'vim'
Correct answer: git config --global core.editor 'vim'
The `core.editor` setting in Git configuration specifies which text editor to launch when Git needs input such as a commit message.
Question 5: What is a `.gitignore` file used for?
- Listing files that Git will automatically commit
- Specifying file patterns that Git should not track or commit (Correct answer)
- Configuring remote repositories
- Storing commit message templates
Correct answer: Specifying file patterns that Git should not track or commit
A `.gitignore` file contains patterns of file names and directories that Git should ignore when determining untracked files.
Question 6: How do you unset a specific Git configuration value?
- git config --delete user.email
- git config --unset user.email (Correct answer)
- git config user.email --remove
- git config --clear user.email
Correct answer: git config --unset user.email
The `git config --unset <key>` command removes the specified setting from the relevant configuration file.
Which command sets your global Git username?