After installing Git, the first thing every developer should do is configure it.
Many beginners simply copy and paste the following commands without understanding what they actually do:
git config --global user.name "John Doe"
git config --global user.email "john@example.com"
These commands work, but understanding why they are needed is far more important.
Every time you create a commit, Git records information about the author, the time of the commit, and many other settings. These settings are stored in Git's configuration files.
Git allows configuration at three different levels:
System
Global
Local
Each level has a different purpose and priority.
In this article, you will learn how Git stores configuration, how to view and modify settings, and how Git decides which configuration to use.
What is Git Configuration?
Git configuration is the collection of settings that control how Git behaves.
These settings tell Git things like:
Your name
Your email address
Which text editor to use
Which default branch to create
How colors should appear
Which merge strategy to use
How credentials should be stored
Without configuration, Git cannot properly identify who created a commit.
Why Does Git Need Your Name and Email?
Every commit in Git contains metadata.
Metadata is information about the commit.
For example:
Commit ID:
9d45f78...
Author:
Rahul Sharma
Email:
rahul@gmail.com
Date:
15 July 2026
Message:
Added Login Feature
Git stores the author's identity permanently inside every commit.
This allows teams to know:
Who made the change?
When was it made?
Which commit introduced a feature or bug?
The Git Configuration Hierarchy
Git stores configuration in three levels.
System Configuration
↓
Global Configuration
↓
Local Configuration
When Git looks for a setting, it checks them in the following order:
Local
Global
System
The first matching setting is used.
1. System Configuration
System configuration affects every user on the computer.
It is mainly used by:
System administrators
Organizations
Shared computers
Typical examples:
Company-wide Git editor
Corporate proxy settings
Default merge tools
System configuration is rarely changed by beginners.
Location
Windows
C:\Program Files\Git\etc\gitconfig
Linux
/etc/gitconfig
macOS
/usr/local/etc/gitconfig
View System Configuration
git config --system --list
Administrator privileges may be required.
2. Global Configuration
Global configuration is the most commonly used level.
It applies only to your user account.
Every repository you create automatically uses these settings unless overridden locally.
Most developers configure Git globally once and rarely change it.
Examples
Your name
git config --global user.name "Rahul Sharma"
Your email
git config --global user.email "rahul@gmail.com"
Default editor
git config --global core.editor "code --wait"
Enable colors
git config --global color.ui auto
Global Configuration File
Windows
C:\Users\Username\.gitconfig
Linux/macOS
~/.gitconfig
3. Local Configuration
Local configuration applies only to one repository.
Every Git repository has its own local configuration.
This allows different projects to have different settings.
Example
Suppose you work for two companies.
Company A uses:
rahul@companyA.com
Company B uses:
rahul@companyB.com
Instead of changing your global email every time, you can configure each repository separately.
Inside Company A's project:
git config user.email "rahul@companyA.com"
Inside Company B's project:
git config user.email "rahul@companyB.com"
Each repository remembers its own configuration.
Local Configuration File
Every repository contains:
.git/config
This file stores repository-specific settings.
Configuration Priority
Suppose Git finds the following email addresses:
System:
admin@company.com
Global:
rahul@gmail.com
Local:
rahul@office.com
When you make a commit inside that repository, Git uses:
rahul@office.com
because Local has the highest priority.
Viewing Git Configuration
Display All Settings
git config --list
Example output:
user.name=Rahul Sharma
user.email=rahul@gmail.com
core.editor=code --wait
color.ui=auto
View Only Your Name
git config user.name
View Only Email
git config user.email
View Global Name
git config --global user.name
View Local Name
git config --local user.name
Setting Your Name
git config --global user.name "Rahul Sharma"
Git stores this name inside every commit.
Setting Your Email
git config --global user.email "rahul@gmail.com"
Always use the email linked to your GitHub account if you plan to push code to GitHub.
Changing Configuration
Changing your name is simple.
git config --global user.name "Amit Kumar"
The previous value is replaced.
The same applies to your email.
Removing Configuration
You can remove settings if they are no longer needed.
Example:
git config --global --unset user.email
Similarly:
git config --global --unset user.name
Listing Configuration Sources
Sometimes you may want to know where each setting comes from.
Run:
git config --list --show-origin
Example output:
file:C:/Users/Rahul/.gitconfig
user.name=Rahul Sharma
file:C:/Users/Rahul/.gitconfig
user.email=rahul@gmail.com
This helps identify whether a setting comes from the System, Global, or Local configuration.
Common Configuration Options
Default Editor
Visual Studio Code
git config --global core.editor "code --wait"
Vim
git config --global core.editor "vim"
Nano
git config --global core.editor "nano"
Enable Colored Output
git config --global color.ui auto
Colored output makes Git messages easier to read.
Default Branch Name
git config --global init.defaultBranch main
Every new repository will now start with the main branch.
Credential Storage
Store credentials securely:
git config --global credential.helper manager
Windows users commonly use Git Credential Manager.
Common Beginner Mistakes
Mistake 1
Using the wrong email address.
Always use the email associated with your GitHub account if you want your commits to appear under your GitHub profile.
Mistake 2
Typing --global inside a repository when you only want to change that specific project.
Remember:
--globalaffects all repositories.No flag (inside a repository) affects only the current repository.
Mistake 3
Editing .gitconfig manually without understanding the syntax.
Use Git commands whenever possible.
Best Practices
Configure your name and email immediately after installing Git.
Use your real name for professional projects.
Keep one global configuration for personal work.
Use local configuration for company or client repositories if needed.
Use
git config --listregularly to verify your settings.
Summary
Git configuration controls how Git behaves and how it identifies you as a developer. Git stores settings at three levels: System, Global, and Local. The Local configuration has the highest priority, followed by Global and then System.
Most developers only need to configure their Global settings once, but Local configuration is useful when working on projects that require different identities or custom settings.
Understanding Git configuration is essential because every commit you create includes the information defined by these settings.
Frequently Asked Questions (FAQs)
1. What is Git configuration?
Git configuration is a set of settings that control Git's behavior, such as your name, email, editor, and default branch.
2. Which configuration level has the highest priority?
Local configuration has the highest priority, followed by Global and then System.
3. Where is Global configuration stored?
In the .gitconfig file inside your user profile directory.
4. Can I use different email addresses for different projects?
Yes. Configure different email addresses using Local configuration inside each repository.
5. How can I see all my Git settings?
Run:
git config --list
Comments
Post a Comment