Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Files and Formats

The .gitconfig file format

Reference for the Git configuration file format: sections, subsections, variable syntax, quoting and escapes, comments, value types, and the files Git reads.

Every Git configuration file, whether ~/.gitconfig, .git/config or .gitmodules, uses one small INI-like format. A file is a list of sections, each holding name = value variables. git config edits these files for you, but understanding the syntax lets you read them, repair them, and write them by hand or by script.

Git reads several files in a fixed order and later ones win: system, then global (user), then the repository's .git/config, then a per-worktree file, then -c options and GIT_CONFIG_* environment variables.

Terminal
[user]
    name = Ada Lovelace
[remote "origin"]
    url = https://example.com/repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*

Try it

Bash Read the file Git wrote

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 Quoting, comments and value types

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
[section]
[section "subsection"]
name = value
name
# comment
; comment
Element Rule
Section name Letters, digits and -; case-insensitive. [core].
Subsection In double quotes, any characters except newline and NUL; case-sensitive. Escape " and \ with a backslash. The old [section.subsection] form lowercases the name.
Variable name Starts with a letter; letters, digits and -; case-insensitive.
name = value Whitespace around = and at the ends of an unquoted value is dropped.
name alone A variable with no = is treated as boolean true.
Quoting Double quotes preserve leading and trailing spaces and make # and ; literal.
Escapes \n, \t, \b, \" and \\. A backslash at the end of a line continues the value.
Comments # or ; outside quotes, to the end of the line.
Multi-valued A variable may appear many times (fetch, url); --get-all lists them.

Value types: boolean (true/yes/on/1 and false/no/off/0, or empty), integer (optional k, m, g suffix as a multiplier), path (~/ and ~user/ expand; %(prefix)/ is replaced by Git's install prefix), color and expiry date.

Usage notes

  • Where each file lives. System: /etc/gitconfig (or $(prefix)/etc); global: ~/.gitconfig and $XDG_CONFIG_HOME/git/config; local: .git/config; worktree: .git/config.worktree when extensions.worktreeConfig is enabled.
  • git config --show-origin prints the file and line of each value, and --show-scope the level.
  • Lowercase on read. git config --list shows section and variable names in lowercase but keeps subsection case.
  • Scalar vs list. git config key value replaces a single value and fails if there are several; use --add, --replace-all or --unset-all for lists.
  • Values with # or ; need quotes, or the rest is silently a comment (a classic source of broken URLs and aliases).
  • Includes. [include] and [includeIf] pull in other files; see include and includeIf.
  • Safe to hand-edit, but a syntax error makes every Git command in that repository fail with "bad config line N in file". Fix the line named in the message.
  • Security. Settings such as core.fsmonitor or core.sshCommand run programs, which is why repository-local config from untrusted sources deserves care.