Quick Setup: Git Global Configuration
If you are setting up Git for the first time, use the following commands to configure your identity globally using
git config. These settings will apply to all repositories on your system.
Set username and email
Run the following commands:
git config --global user.name "Your Name"
git config --global user.email "your@email.com"These values will be used in every commit you make with
git commit.
Verify global configuration
To confirm your configuration:
git config --listYou can also check specific values:
git config user.name
git config user.emailWhat is git config --global?
The git config --global command is used to set configuration values that apply to all Git repositories for the current user.
Why global configuration is important
- Avoids setting username and email for every repository
- Ensures consistent commit identity
- Required for making commits without errors using
git commit - Simplifies initial Git setup
Where git global config is stored (~/.gitconfig)
Global configuration is stored in the following file:
~/.gitconfigYou can view it using:
cat ~/.gitconfigGit Configuration Levels Explained
Global vs local vs system configuration
Local configuration (
--local)- Applies only to a specific repository created using
git init - Stored in
.git/config - Highest priority
- Applies only to a specific repository created using
Global configuration (
--global)- Applies to the current user
- Stored in
~/.gitconfig
System configuration (
--system)- Applies to all users on the system
- Stored in
/etc/gitconfig - Lowest priority
Order of precedence
When multiple configurations exist, Git follows this order:
- Local configuration (highest priority)
- Global configuration
- System configuration (lowest priority)
This means local settings override global settings, and global settings override system settings.
Common Git Global Config Commands
Set username
Set your name, which will appear in your commits:
git config --global user.name "Your Name"Set email
Set your email address used for commits:
git config --global user.email "your@email.com"Set default editor
Configure your preferred editor (for writing messages with git commit, etc.):
git config --global core.editor vimYou can replace vim with editors like nano, code, or vi.
Set default branch name
Set the default branch name when initializing new repositories with
git init:
git config --global init.defaultBranch mainHow to Check Git Configuration
List all configuration values
Display all Git configuration settings:
git config --listGet specific config values
Retrieve individual configuration values:
git config user.name
git config user.email
git config core.editorGit Config File Location in Linux
Git stores configuration settings in different files based on scope.
Global config file path
Global configuration is stored in:
~/.gitconfigView it using:
cat ~/.gitconfigSystem config file path
System-wide configuration is stored in:
/etc/gitconfigThis requires root privileges to edit.
Repository config file path
Local repository configuration is stored in:
.git/configThis applies only to the current repository.
First-Time Git Setup
Configure username and email
git config --global user.name "Your Name"
git config --global user.email "your@email.com"Set editor and default branch
git config --global core.editor vim
git config --global init.defaultBranch mainVerify setup
git config --listEnsure all values are correctly set before starting to use Git repositories created using
git init or
git clone.
Common Issues with git config
Wrong username or email in commits
If commits created using git commit show incorrect details:
- Update configuration using
git config --global - Or set repository-specific values using
--local
Configuration not applied
If settings are not applied:
- Ensure you used
--globalor--localcorrectly - Restart terminal if needed
- Verify using
git config --list
Multiple config conflict
Conflicts occur when the same setting exists in multiple levels:
- Local config overrides global
- Global overrides system
To debug:
git config --list --show-originThis shows where each configuration value is defined.
Frequently Asked Questions
1. What is git config --global used for?
The git config --global command is used to set configuration values like username and email globally for all repositories on your system.2. How do I set username and email in Git?
You can set them using git config --global user.name and git config --global user.email commands.3. Where is git global config stored?
Git global configuration is stored in the ~/.gitconfig file.4. What is the difference between global and local git config?
Global config applies to all repositories, while local config applies only to a specific repository.5. How do I check my git configuration?
You can check configuration using git config --list or view the ~/.gitconfig file.Summary
In this guide, you learned how to configure Git globally using the git config --global command.
- Set username and email for commits
- Configure editor and default branch
- Understand configuration levels (local, global, system)
- Verify and troubleshoot configuration issues
Proper Git configuration ensures consistent commit identity and a smooth development workflow when working with repositories created using
git init.


