Skip to main content

Git Configuration

Git provides extensive configuration options to customize your workflow. You can configure settings globally (for all repositories) or locally (for the current repository).

User Configuration

Configuring Git user information is essential to associate commits with a user. This information is used to identify the author of a commit and is displayed in the commit history.

Set User Information

You can use git config to specify user information either globally or locally:
# Configure user for current repository
git config user.email "[email protected]"
git config user.name "Duck Quackers"

# Configure global Git user
git config --global user.email "[email protected]"
git config --global user.name "Duck Quackers"

Editing Configuration Files

Using git config repeatedly can be tedious. Instead, you can open the Git configuration file directly in your text editor.

Open Configuration File

Use git config -e to open the Git configuration file in the default Git text editor:
git config --global -e
# Opens the global git configuration file in the default git text editor

git config -e
# Opens the local repository git configuration file in the text editor
This allows you to make multiple changes at once without having to remember specific commands for each setting.

Configuration Levels

Git has three levels of configuration:

System Level

Applies to all users on the system and all their repositories:
git config --system <key> <value>

Global Level

Applies to all repositories for the current user:
git config --global <key> <value>

Local Level

Applies only to the current repository:
git config <key> <value>

Viewing Configuration

You can view your current Git configuration at any time:
# View all configuration settings
git config --list

# View a specific setting
git config user.name

# View global configuration
git config --global --list

Common Configuration Options

Here are some commonly configured Git settings:
# Set default branch name
git config --global init.defaultBranch main

# Enable colored output
git config --global color.ui auto

# Set default text editor
git config --global core.editor "code --wait"

# Configure line endings
git config --global core.autocrlf input

Configuration File Format

Git configuration files use the INI file format:
~/.gitconfig
[user]
  name = Duck Quackers
  email = [email protected]

[core]
  editor = code --wait
  autocrlf = input

[init]
  defaultBranch = main

[color]
  ui = auto

Best Practices

  • Always configure your user information before making commits
  • Use global configuration for settings that apply to all your projects
  • Use local configuration for project-specific settings
  • Keep sensitive information out of configuration files
  • Review your configuration periodically to ensure it matches your workflow

Build docs developers (and LLMs) love