Configuring Git: git config for Username, Email, Editor, and Core Settings
Once Git is installed, it doesn't yet know who you are. Every commit you make needs to be attributed to a name and email address, and Git will refuse to let you commit meaningfully until this identity is configured. This lesson covers the `git config` command in depth — how to set your identity, choose a default text editor for writing commit messages, and understand the different levels at which configuration can apply.
Learning Objectives
- Set a global username and email using git config.
- Configure a default text editor for Git to use (e.g., VS Code, Vim, Nano).
- Understand the three levels of Git configuration: system, global, and local.
- View and verify current configuration settings.
Key Terms to Know Before Learning Configuring Git
- git config: The command used to get and set configuration options that control Git's behavior, at various scopes.
- System level config: Settings that apply to every user on the machine, stored in a file managed by the system administrator.
- Global level config: Settings that apply to all repositories for the current user, typically stored in ~/.gitconfig.
- Local level config: Settings that apply only to a single specific repository, stored in that repository's .git/config file.
- Default editor: The text editor Git opens automatically when a command (like `git commit` without a -m flag) requires you to write a message.
How Configuring Git Actually Works
Git configuration exists at three levels, each overriding the one before it in scope:
1. **System** (`--system`): Applies to every user and every repository on the entire machine. Rarely used by individual developers; typically set by system administrators.
2. **Global** (`--global`): Applies to all repositories for the currently logged-in user. This is where you'll set your name and email the very first time you use Git on a machine — it's a one-time setup per machine/user.
3. **Local** (`--local`, the default when no flag is given, and only valid inside a repository): Applies only to the one specific repository you're currently in, and overrides global settings for that repo. Useful when you want a different email for a specific project — for example, using a work email for company repositories and a personal email for open-source contributions.
The two most essential settings to configure immediately after installing Git are your username and email, since every commit you create permanently records this information as its author:
```
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
```
Without this, many versions of Git will block commits entirely or attach a placeholder identity, which looks unprofessional and makes it impossible to properly attribute your work — especially important on shared platforms like GitHub, which match commits to your account based on this email.
Another important setting is your default editor — the program Git opens when a command needs you to type a longer message (such as running plain `git commit` without the `-m` flag, or during an interactive rebase). By default, Git often opens Vim, which can be confusing for beginners unfamiliar with its modal editing (to exit Vim without saving: press Esc, then type `:q!` and press Enter). Many beginners prefer setting a more familiar editor like VS Code or Nano:
```
git config --global core.editor "code --wait"
```
Finally, `git config --list` shows all currently active settings (merged across system, global, and local levels), and `git config --list --show-origin` additionally shows which file each setting came from — useful for debugging unexpected configuration behavior.
Configuring Git: Visual Walkthrough
Draw three concentric boxes, largest to smallest, labeled from outside in: 'System (--system): all users, all repos', 'Global (--global): current user, all their repos', 'Local (--local): one specific repository'. An arrow labeled 'increasing precedence' points from the outer box to the inner box, showing that local settings override global, which override system.
Configuring Git: Quick Reference Table
| Config Level | Flag | Scope | Typical File Location |
|---|---|---|---|
| System | --system | Every user, every repo on the machine | /etc/gitconfig |
| Global | --global | Current user, all their repositories | ~/.gitconfig |
| Local | --local (default) | One specific repository only | .git/config inside the repo |
Configuring Git: Command Syntax and Examples
# Set your identity globally (once per machine)
git config --global user.name "Asha Mehta"
git config --global user.email "asha.mehta@example.com"
# Set a default editor for commit messages
git config --global core.editor "code --wait"
# Override email for one specific repository only (run inside that repo)
git config user.email "asha@company.com"
# View all active settings
git config --list
# View a single setting
git config user.name
# See which file each setting comes from
git config --list --show-origin
Breaking Down the Configuring Git Example
The first two commands set Asha's name and email globally, meaning every repository on her machine will attribute her commits to this identity unless overridden. The third command, run without `--global` inside a specific repository, sets a local override — useful if that particular project (say, a work repo) needs a different email than her personal default. `git config --list` then confirms every setting currently in effect, while `--show-origin` reveals exactly which configuration file each value was read from, which is invaluable when settings seem to behave unexpectedly across different repositories.
How Configuring Git Is Used on Real Engineering Teams
- Companies often require developers to configure a company email (`user.email`) locally for work repositories to ensure commit attribution matches internal HR and access records.
- Open-source contributors frequently keep a global personal email configured, but override it locally per-repo when contributing under a pseudonym or separate identity for privacy.
- Development teams standardize on `core.editor` settings in onboarding documentation so every new hire's commit message experience (e.g., opening VS Code instead of Vim) is consistent and less error-prone.
- CI/CD systems (like GitHub Actions or Jenkins) set `user.name` and `user.email` via config commands in build scripts so automated commits (e.g., version bump commits) are properly attributed to a bot identity.
Configuring Git Interview Questions and Answers
Q1. What is the purpose of git config and what are its three levels?
`git config` sets and retrieves configuration options that control Git's behavior. It operates at three levels: system (applies to all users on the machine), global (applies to all repositories for the current user), and local (applies only to a single repository, overriding global and system settings for that repo).
Q2. Why is setting user.name and user.email important before making commits?
Every Git commit permanently records an author name and email as part of its metadata. Without configuring these, Git may block commits or attach a generic placeholder identity, making it impossible to correctly attribute changes — which is especially important on platforms like GitHub that match commits to user accounts by email.
Q3. How would you set a different email for one specific project without affecting your global settings?
Run `git config user.email "work@company.com"` (without the `--global` flag) from inside that specific repository. This creates a local-level setting stored in that repo's `.git/config` file, which takes precedence over the global email for that repository only.
Configuring Git Quiz: Test Your Understanding
1. Which command sets your Git username globally for all repositories?
- git config user.name "Name"
- git config --global user.name "Name"
- git set username "Name"
- git --global-user "Name"
Answer: B. git config --global user.name "Name"
Explanation: The `--global` flag applies the setting to all repositories for the current user, which is the correct way to set a default identity across all projects.
2. Which configuration level takes precedence when local and global settings conflict?
- System
- Global
- Local
- They are averaged
Answer: C. Local
Explanation: Local repository-level settings override global settings, which in turn override system-wide settings — local is the most specific and therefore takes highest precedence.
3. What command lists all currently active Git configuration settings?
- git config --show
- git config --list
- git settings --all
- git status --config
Answer: B. git config --list
Explanation: `git config --list` displays every configuration setting currently in effect, merged across system, global, and local levels.
4. Which setting controls which text editor Git opens for writing commit messages?
- core.editor
- user.editor
- commit.tool
- git.defaulteditor
Answer: A. core.editor
Explanation: `core.editor` is the configuration key used to specify the program Git should open when a text editor is needed, such as during a `git commit` without a message flag.
Configuring Git: Common Mistakes Beginners Make
- Forgetting the --global flag and unintentionally setting user.name or user.email only for the current repository.
- Never setting an identity at all and being confused when Git blocks a commit with an 'author identity unknown' error.
- Getting stuck in Vim (Git's default editor on many systems) and not knowing how to exit — press Esc, then type :q! and Enter to quit without saving.
- Using a personal email globally and forgetting to override it locally for work repositories, leading to commits misattributed on company systems.
Configuring Git: Exam-Ready Quick Notes
- Three config levels: system, global, local — local overrides global overrides system.
- Essential first-time setup: `git config --global user.name` and `git config --global user.email`.
- `git config --list` shows all active settings; add `--show-origin` to see which file each came from.
Configuring Git: Key Takeaways
- Configuring your identity with git config is a mandatory first step before making meaningful commits.
- Git configuration works in layers — local settings override global, which override system — giving flexibility for per-project customization.
- Setting a familiar default editor with core.editor avoids the common beginner problem of getting stuck in Vim.
Frequently Asked Questions About Configuring Git
Q1. How do I set my name and email in Git?
Run `git config --global user.name "Your Name"` and `git config --global user.email "you@example.com"`. These settings are used to attribute every commit you make across all your repositories.
Q2. What happens if I don't configure user.name and user.email?
Git will often refuse to let you commit, showing an error about an unknown author identity, or in older versions it may attach a generic placeholder identity to your commits, which is not useful for tracking authorship.
Q3. How can I use a different email for just one project?
Navigate into that project's repository and run `git config user.email "other@example.com"` without the `--global` flag. This creates a local override that applies only to that specific repository.
Q4. How do I stop Git from opening Vim for commit messages?
Set a different default editor with `git config --global core.editor "code --wait"` (for VS Code) or `git config --global core.editor "nano"` (for Nano), replacing Vim as the program Git opens.
Q5. How do I check my current Git configuration settings?
Run `git config --list` to see all active settings, or `git config user.email` to check a single specific value. Add `--show-origin` to also see which configuration file each setting is coming from.
Summary
`git config` is the command used to set and inspect Git's behavior at three levels: system-wide, per-user (global), and per-repository (local), with more specific levels overriding broader ones. The two most essential first-time settings are `user.name` and `user.email`, since every commit permanently records this author information. Configuring `core.editor` lets you choose a familiar text editor instead of Git's often-confusing default. `git config --list` (optionally with `--show-origin`) lets you inspect and verify your current configuration at any time.