Git - Config

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





Discover More
Git - Client Installation

Git for windows provides a bash and a gui. It provides also all GNU core utility where: the global option tells Git to store the parameters on a global scope...
Git - Credential

Git makes use of a credential helper (an external utility) to be able to retrieve the credentials) The id of a credential (user, ww) is a URL (Credential context) It will lookup a credential with the...
Git - Git (executable|command line)

The git executable where: --git-dir is the location of the repository files --work-tree is the location of the work tree Command Description add Add file contents to the index add--interactive...
Git - Remote (Tracked Repository)

A remote in Git is a remote repository (ie a remote git server). Git remote manage the set of repositories (“remotes”) whose branches you track. They are also called tracked repositories in reference...
Git - Submodule (modules)

Submodules allow you to keep a Git repository as a subdirectory of another Git repository. package manager A submodule is materialzied as: a subdirectory in your working directory. with its metadata...
Git - Upstream Branch (Tracking branch)

An upstream is a configuration of a local branch that set the remote branch that it's tracking. cloning @{u} or @{upstream} means the upstream branch of the current branch @{upstream} or @{u}...
Git - difftool

This article is the difftool configuration. Is there a diff with the mergetool? meld on linux WinMerge or p4merge on windows git difftool --tool= may be set to one of the following:...
Windows Envrionment Variable Path Shell Script
How to configure Git to use NotePad++ as editor on Windows?

This article shows you how you can configure git to use Notepad++ as editor on your laptop.
How to install and store credentials on Linux with Git Credential Manager and pass?

This article shows you how you can store git credential (username and password) on Linux with: the Git Credential Manager and the gpg/pass...
Git - Repository (Directory)

This page is the notion of repository and how it's implemented in Git. The git repository is a subdirectory named .git that contains all repository files. It contains : commit log configuration,...



Share this page:
Follow us:
Task Runner