跳转到内容

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.

Configure your name and email – this appears in your commits:

Terminal window
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:

Terminal window
git config --global init.defaultBranch main

Makes Git commands more readable:

Terminal window
git config --global color.ui auto

Configure your preferred editor for commit messages:

Terminal window
# 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"

Verify your configuration:

Terminal window
git config --list
  • Line Ending Handling (Critical for cross-OS work):

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

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

    Terminal window
    git config --global push.default current

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

Terminal window
git config user.email "work.email@company.com"
  • Global: ~/.gitconfig (Linux/macOS) or C:\Users\username\.gitconfig (Windows)
  • Local: .git/config in each repository

Example minimal setup:

Terminal window
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

View all settings with this command:

Terminal window
git config --list --show-origin

Get a single setting with this command:

Terminal window
git config --get user.name

If you want to get a setting in a particular location, such as global, system or local configration:

Terminal window
git config --get --global user.email

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!