Git Configuration
Before starting to use Git, it needs to know who is making the changes. This is done through Git configuration — setting up a name and email address that will be attached to every commit. This information helps teams know who made which change.
Think of it like signing a document. Before submitting work, a signature is required. Git requires a name and email as that "signature" before any commits can be made.
Three Levels of Git Configuration
Git has three levels of configuration, each with a different scope:
| Level | Flag | Scope | Config File Location |
|---|---|---|---|
| System | --system | All users on the machine | /etc/gitconfig |
| Global | --global | Current logged-in user | ~/.gitconfig |
| Local | --local | Current project/repository only | .git/config (inside the project) |
For most users, the global level is the right choice — it applies settings to all projects on the machine.
Setting Up Username and Email
These are the two most essential configurations. Run these commands once after installing Git:
git config --global user.name "Ravi Kumar"
git config --global user.email "ravi.kumar@example.com"
Replace the name and email with actual name and email — preferably the same email used for a GitHub account.
Verifying the Configuration
To check that everything is set correctly:
git config --global user.name
git config --global user.email
Or to see all configurations at once:
git config --listSample output:
user.name=Ravi Kumar
user.email=ravi.kumar@example.com
core.editor=code
Setting the Default Text Editor
Git sometimes opens a text editor — for example, when writing a commit message. By default, it may open a terminal-based editor like Vim, which can be confusing for beginners. It can be changed to a preferred editor:
Set Visual Studio Code as Default Editor
git config --global core.editor "code --wait"Set Notepad++ (Windows) as Default Editor
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -nosession"Set Nano (Simple Terminal Editor) as Default
git config --global core.editor "nano"Setting the Default Branch Name
By default, older versions of Git name the first branch master. Newer convention uses main. To set this globally:
git config --global init.defaultBranch mainConfiguring Line Endings
Windows and Linux/macOS use different characters to mark the end of a line in text files. This can cause issues when collaborating. Git can handle this automatically:
On Windows
git config --global core.autocrlf trueOn macOS/Linux
git config --global core.autocrlf inputViewing the Configuration File Directly
The global configuration is stored in a file called .gitconfig in the home directory. To open and view it directly:
git config --global --editA sample .gitconfig file looks like this:
[user]
name = Ravi Kumar
email = ravi.kumar@example.com
[core]
editor = code --wait
autocrlf = input
[init]
defaultBranch = main
Removing a Configuration Setting
To remove a specific configuration option:
git config --global --unset user.nameLocal vs Global Configuration — A Practical Example
Suppose there are two projects on the same machine — one personal project and one work project. Different email addresses can be used for each:
# Set global (default) email for all projects
git config --global user.email "personal@example.com"
# Inside the work project folder, override with work email
cd /path/to/work-project
git config --local user.email "work@company.com"
Now the personal email is used for all other projects, but the work email is used only inside the work project.
Useful Configuration Options at a Glance
| Command | Purpose |
|---|---|
git config --global user.name "Name" | Set the author name |
git config --global user.email "email" | Set the author email |
git config --global core.editor "code --wait" | Set default editor |
git config --global init.defaultBranch main | Set default branch name |
git config --list | Show all configurations |
git config --global --edit | Open the config file in editor |
Summary
Git configuration sets up an identity (name and email) that gets attached to every commit. The global level applies to all projects on the machine, while the local level applies to a single project. Run git config --list anytime to confirm the current settings are correct.
