git-config
Configure Git settings
TLDR
Globally set your name or email (this information is required to commit to a repository and will be included in all commits)
List local, global or system configuration entries and show their file location
Set the global value of a given configuration entry (in this case an alias)
Get the value of a given configuration entry
Use an alias
Revert a global configuration entry to its default value
Edit the local Git configuration (.git/config) in the default editor
Edit the global Git configuration (~/.gitconfig by default or $XDG_CONFIG_HOME/git/config if such a file exists) in the default editor
SYNOPSIS
git config [--local | --global | --system | --worktree | -f <file> | --blob <blob-id>] [--type=<type>] [--add | --get | --get-all | --get-regexp=<regexp> | --replace-all | --unset | --unset-all | --rename-section | --remove-section | --list | --edit | --get-color | --get-colorbool] [--name-only] [--null] [<key> [<value> [<value_regexp>]]]
PARAMETERS
--local
Operates on the repository-specific configuration file (.git/config). This is the default when no scope option is given.
--global
Operates on the current user's global configuration file (~/.gitconfig on Unix, or %HOMEDRIVE%%HOMEPATH%\.gitconfig on Windows).
--system
Operates on the system-wide configuration file ($(prefix)/etc/gitconfig).
--worktree
Operates on the current worktree's configuration file. Each worktree can have its own specific configuration.
-f <file>, --file <file>
Use a specific configuration file instead of the default ones.
--get <key>
Get the value for a given key. Only the first value is returned if multiple exist.
--set <key> <value>
Set a new value for a configuration key. If the key already exists, its value is overwritten.
--add <key> <value>
Add a new line to the option, allowing multiple values for a single key. Useful for things like remote URLs.
--unset <key>
Remove the first line matching the given key. Returns an error if no such key exists.
--unset-all <key>
Remove all lines matching the given key. Returns an error if no such key exists.
--list
List all variables set in the configuration file(s). Can be combined with scope options to filter.
--edit
Open an editor to manually edit the configuration file of the specified scope (or local by default).
--type=<type>
Specify the type of value to be retrieved or set. Can be 'bool', 'int', 'path', 'bool-or-int', 'string'.
--name-only
When used with --list or --get-regexp, list only the names of the variables, not their values.
--null
When used with --list or --get-regexp, terminate output lines with NUL bytes instead of newlines.
DESCRIPTION
The git config command is a utility that allows users to get and set configuration variables for their Git installations or specific repositories. These variables control virtually every aspect of Git's behavior, from user identity and default editor to merge strategies and alias definitions. It's fundamental for customizing Git to suit individual workflows or project requirements. Users can read individual values, list all settings, or modify existing ones across different scope levels: system-wide, per-user, or specific to a particular repository or even a worktree. This command provides a powerful interface for fine-tuning Git's operations.
CAVEATS
Understanding the configuration hierarchy is critical: options from the local level override global, which override system. This cascading behavior means that a setting in your project's .git/config will take precedence over a setting in your ~/.gitconfig. Incorrectly configured options can lead to unexpected Git behavior or prevent operations from completing as desired.
CONFIGURATION LEVELS
Git reads configuration from multiple files, organized in a hierarchy:
1. System-wide ($(prefix)/etc/gitconfig): Applies to all users on the system.
2. Global (~/.gitconfig or $XDG_CONFIG_HOME/git/config): Applies to a specific user.
3. Repository-local (.git/config): Applies only to the current repository.
4. Per-worktree (.git/config within a worktree directory): Applies only to a specific worktree.
Settings at lower levels override those at higher levels.
VARIABLE NAMING
Configuration variables are typically organized into hierarchical sections and subsections, separated by dots. For example, user.name and core.editor. Section names are often followed by a value in quotes, e.g., [user]
name = John Doe. The command line often uses the full dot-separated path, like user.name, for simplicity.
HISTORY
git-config has been a core component of Git since its early days, providing the primary interface for managing Git's myriad of configurable options. Over time, its capabilities have expanded, notably with the introduction of per-worktree configuration in Git 2.15, allowing even finer-grained control over multi-worktree setups. Its fundamental design remains consistent, reflecting Git's philosophy of being highly customizable.