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)

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"

Since version 2.28, Git uses main as the default branch instead of master:

git config --global init.defaultBranch main

Makes Git commands more readable:

git config --global color.ui auto

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

Verify your configuration:

git config --list

Additional Useful Settings

  • Line Ending Handling (Critical for cross-OS work):

    # Windows
    git config --global core.autocrlf true
    
    # Linux/macOS
    git config --global core.autocrlf input
  • Enable Credential Helper (Saves auth info):

    # Cache credentials for 15 minutes
    git config --global credential.helper cache
  • Set Default Push Behavior:

    git config --global push.default current

Repository-Specific Settings

Override global config per-repo (run inside repo directory):

git config user.email "work.email@company.com"

Where Config is Stored:

  • Global: ~/.gitconfig (Linux/macOS) or C:\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 main
git config --global color.ui auto

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

We can remove settings by using git config --[local/global/system] --unset user.name to remove a setting.

After configuration, you’re ready to:

  1. git init (create new repo)
  2. git clone (copy existing repo)
  3. Start making commits!