Git config
After installing Git, the first and most important thing is to set up your identity. And you should configure some core settings.
Read the whole guide first, then set up your config. Don’t do it before read the whole guide.
Set Your Identity (Essential)
Section titled “Set Your Identity (Essential)”Configure your name and email – this appears in your commits:
git config --global user.name "Your Name"git config --global user.email "your.email@example.com"
Set Default Branch Name (Recommended)
Section titled “Set Default Branch Name (Recommended)”Since version 2.28, Git uses main
as the default branch instead of master
:
git config --global init.defaultBranch main
Enable Color Output (Recommended)
Section titled “Enable Color Output (Recommended)”Makes Git commands more readable:
git config --global color.ui auto
Set Default Text Editor
Section titled “Set Default Text Editor”Configure your preferred editor for commit messages:
# For VSCode:git config --global core.editor "code --wait"
# For Nano:git config --global core.editor "nano"
# For Vim:git config --global core.editor "vim"
Check Your Settings
Section titled “Check Your Settings”Verify your configuration:
git config --list
Additional Useful Settings
Section titled “Additional Useful Settings”-
Line Ending Handling (Critical for cross-OS work):
Terminal window # Windowsgit config --global core.autocrlf true# Linux/macOSgit config --global core.autocrlf input -
Enable Credential Helper (Saves auth info):
Terminal window # Cache credentials for 15 minutesgit config --global credential.helper cache -
Set Default Push Behavior:
Terminal window git config --global push.default current
Repository-Specific Settings
Section titled “Repository-Specific Settings”Override global config per-repo (run inside repo directory):
git config user.email "work.email@company.com"
Where Config is Stored:
Section titled “Where Config is Stored:”- Global:
~/.gitconfig
(Linux/macOS) orC:\Users\username\.gitconfig
(Windows) - Local:
.git/config
in each repository
Example minimal setup:
git config --global user.name "Alex Johnson"git config --global user.email "alex@example.com"git config --global init.defaultBranch maingit config --global color.ui auto
How to Get Git Settings
Section titled “How to Get Git Settings”View all settings with this command:
git config --list --show-origin
Get a single setting with this command:
git config --get user.name
If you want to get a setting in a particular location, such as global, system or local configration:
git config --get --global user.email
How to Remove git settings
Section titled “How to Remove git settings”We can remove settings by using git config --[local/global/system] --unset user.name
to remove a setting.
After configuration, you’re ready to:
git init
(create new repo)git clone
(copy existing repo)- Start making commits!