Before you push your first commit or clone your first repository, Git needs to know a few things about you—like who you are and how you want it to behave. That’s where git config
comes in.
Whether you're a beginner or a seasoned developer, understanding how to configure Git properly can save you from identity issues, commit confusion, or merge mishaps.
In this post, we’ll explore what git config
is, common settings, and how to manage Git configuration at different levels.
🧠 What Is git config
?
git config
is the command used to get and set Git options. These options control everything from your username and email to merge behavior, editor preferences, aliases, and more.
Git stores this configuration at three levels:
🔒 1. System-level
Applies to every user and repo on the computer./etc/gitconfig
👤 2. Global-level
Applies to your user account across all repositories.~/.gitconfig
📁 3. Local-level
Applies only to the current repo.<repo>/.git/config
Git uses the most specific level first (local > global > system).
🧾 Basic Setup Commands
Here’s how to set the most important things:
# Set your name
git config --global user.name "Your Name"
# Set your email
git config --global user.email "you@example.com"
These values show up in your commit history and are required for pushing to remotes like GitHub or GitLab.
🛠️ Common Git Configurations
📝 Set Your Default Editor
git config --global core.editor "code --wait" # VS Code
🔄 Configure Merge Tool
git config --global merge.tool vimdiff
🌐 Set Default Branch Name
git config --global init.defaultBranch main
📛 Create Git Aliases
git config --global alias.co checkout
git config --global alias.st status
git config --global alias.cm "commit -m"
These aliases speed up your workflow dramatically.
🔍 View Your Current Configuration
To view all your current global settings:
git config --global --list
To check local repo config:
git config --local --list
You can also check values individually:
git config user.name
git config user.email
❌ Troubleshooting Tip
If you see errors like:
fatal: unable to auto-detect email address
It means your Git identity isn't configured. Run:
git config --global user.email "you@example.com"
💡 Bonus: Use .gitconfig
File
Your global config is stored in:
~/.gitconfig
You can open and edit this manually. Example content:
[user]
name = Your Name
email = you@example.com
[alias]
co = checkout
st = status
cm = commit -m
This is helpful when copying configs across machines or sharing dotfiles.