Table of Contents

About

The git docs/git-config.html command.

Syntax

git config [<file-option>] [type] [-z|--null] name [value [value_regex]]
git config [<file-option>] [type] --add name value
git config [<file-option>] [type] --replace-all name value [value_regex]
git config [<file-option>] [type] [-z|--null] --get name [value_regex]
git config [<file-option>] [type] [-z|--null] --get-all name [value_regex]
git config [<file-option>] [type] [-z|--null] [--name-only] --get-regexp name_regex [value_regex]
git config [<file-option>] [type] [-z|--null] --get-urlmatch name URL
git config [<file-option>] --unset name [value_regex]
git config [<file-option>] --unset-all name [value_regex]
git config [<file-option>] --rename-section old_name new_name
git config [<file-option>] --remove-section name
git config [<file-option>] [-z|--null] [--name-only] -l | --list
git config [<file-option>] --get-color name [default]
git config [<file-option>] --get-colorbool name [stdout-is-tty]
git config [<file-option>] -e | --edit

Resource Location (Section, Key, Value)

The name is actually:

  • the section
  • and the key
  • separated by a dot.

The value will be escaped.

Example:

git config core.editor emacs

where:

  • core.editor is the name whereas:
    • core is the section
    • editor is the key
  • emacs is the value

Type

The type specifier can be either:

  • –int
  • –bool,
  • or –path, which does some path expansion

Data Type Checks or transformations are performed on the value.

  • simple decimal number for int
  • a “true” or “false” string for bool
  • path expansion

Configuration files

The parameters are written to the files that depends of the scope parameter.

Scope Command Option File Details
local (Default) –local .git/config
file –file <filename> <filename>
global –global ~/.gitconfig The tilde ~ means the HOME path
system –system $(prefix)/etc/gitconfig

Configuration Subject

Management

Add

By default, it will add to the repository.

git config --global core.editor emacs

For example: How to configure Git to use NotePad++ as editor on Windows?

List

List the configuration

git config --list
core.symlinks=false
core.autocrlf=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
pack.packsizelimit=2g
help.format=html
http.sslcainfo=C:/Git/mingw64/ssl/certs/ca-bundle.crt
diff.astextplain.textconv=astextplain
rebase.autosquash=true
filter.lfs.clean=git lfs clean %f
filter.lfs.smudge=git lfs smudge %f
filter.lfs.required=true
user.name=Nicolas Gerard
[email protected]
credential.helper=wincred
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
core.hidedotfiles=dotGitOnly

Get

  • with bash
myConfigValue=$(git config myConfigKey)
# example
allownonascii=$(git config hooks.allownonascii)
  • with cat to see all branches at once
cat .git/config
[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
[remote "origin"]
        url = https://github.com/username/reponame.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
        remote = origin
        merge = refs/heads/main

Documentation / Reference