Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Setup and Basics

git config command

Reference for git config: system, global, local and worktree scopes, get/set/unset/list, --show-origin, typed values, multi-valued keys and include files.

git config reads and writes Git's settings. A setting is a dotted key such as user.name or core.autocrlf with a value, stored in plain-text files in INI format. Almost every Git behavior can be tuned this way: identity, aliases, colors, merge and diff behavior, remotes and branch tracking.

Settings come from several files, read in order from broad to narrow. Later files override earlier ones, and command-line -c key=value and environment variables override all of them.

Terminal
git config set [--local|--global|--system] <key> <value>
git config get [--show-origin] <key>
git config list

Try it

Bash Scopes, origins and overrides

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Types, multiple values and editing

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
git config [<scope>] <key>                    # read (old form)
git config [<scope>] <key> <value>            # write (old form)
git config set|get|unset|list|edit [options] # subcommand form

The subcommand form (set, get, unset, list, rename-section, remove-section, edit) was introduced in Git 2.46; the flag-based form (--get, --unset, --list, -e) is still fully supported.

Option Description
--system Machine-wide file (/etc/gitconfig on Linux, in the Git installation folder on Windows). Needs administrator rights to write.
--global Your user file: ~/.gitconfig or $XDG_CONFIG_HOME/git/config.
--local The repository file .git/config. The default when writing inside a repository.
--worktree The per-worktree file, active only when extensions.worktreeConfig is enabled.
-f <file>, --file <file> Use an arbitrary config file.
--blob <rev:path> Read (not write) a config file stored in the repository.
--get <key>, --get-all, --get-regexp <pattern> Read the last value, all values, or all keys matching a regex.
--add <key> <value> Append another value to a multi-valued key.
--unset <key>, --unset-all Remove one value (error if several exist) or all.
--replace-all Replace every value of a key by the new one.
-l, --list Print all settings in effect.
--show-origin, --show-scope Print the file or scope each value comes from.
--type=<type> bool, int, bool-or-int, path, expiry-date, color. Converts and validates (--bool, --int are older spellings).
--default <value> Value to print when the key is missing.
--includes / --no-includes Follow or ignore include directives when reading.
-e, --edit Open the file in your editor.

Exit status: --get returns 1 when the key does not exist. Writing to a key with several values without --replace-all fails with status 5. Naming a file that cannot be written gives status 4.

Usage notes

  • Precedence: system, then global, then local, then worktree, then -c on the command line, then environment variables such as GIT_AUTHOR_NAME. For single-valued keys, the last one wins; for multi-valued keys all values are collected.
  • Where the files live. Local settings travel with the directory but are never pushed or cloned. To share settings with a team, commit a file and load it with include.path, see include and includeIf.
  • Key syntax. section.key or section.subsection.key. Section and key names are case-insensitive; subsection names (a branch name, a remote name) are case-sensitive and may contain dots.
  • Booleans accept true/false, yes/no, on/off, 1/0. A bare key with no value counts as true.
  • Values with spaces or special characters are quoted in the file; the command handles that for you. A # or ; outside quotes starts a comment.
  • Never put secrets in configuration that you might share. Use a credential helper for passwords and tokens.
  • Typos fail silently. Git ignores unknown keys, so git config user.nmae x succeeds. Check with git config --list --show-origin when behavior seems unchanged.
  • Conditional settings (a different identity for work folders) use includeIf in the global file.