Skip to content

config Git Command Guide

The git config command allows you to get and set configuration values that control Git’s behavior. It can set values at local, global, or system level, affecting repository settings, user identity, and Git’s operation.

Terminal window
git config [<options>] [<scope>] <name> [<value> [<value-pattern>]]
git config [<options>] [<scope>] --unset <name> [<value-pattern>]
git config [<options>] [<scope>] --unset-all <name> [<value-pattern>]
git config [<options>] <scope> --replace-all <name> <value> [<value-pattern>]
git config [<options>] <scope> --add <name> <value>
git config [<options>] <scope> --get <name> [<value-pattern>]
git config [<options>] <scope> --get-all <name> [<value-pattern>]
git config [<options>] <scope> --get-regexp <name-regex>
git config [<options>] [<scope>] --get-urlmatch <name> <URL>
git config [<options>] --unset-all <section> <key> [<value-pattern>]
git config [<options>] --rename-section <old-name> <new-name>
git config [<options>] --remove-section <name>
git config [<options>] <scope> --list [<pattern>]
OptionDescription
—localRead/write from local .git/config file (repository-specific)
—globalRead/write from ~/.gitconfig or ~/.config/git/config (user-specific)
—systemRead/write from $(prefix)/etc/gitconfig (system-wide)
—worktreeRead/write from .git/config.worktree (worktree-specific)
—file Use given config file instead of default
—blob Read config from given blob object
—getGet value (optional, defaults to listing)
—get-allGet all values that match key
—get-regexpGet values for all keys matching regex
—get-urlmatch Get value specific to given URL
—replace-allReplace all matching values with given value
—addAdd new value without replacing
—unsetRemove matching values
—unset-allRemove all values
—rename-sectionRename section
—remove-sectionRemove section
—listList all options
—type Ensure value is of given type (bool, int, string, etc.)
—boolEnsure value is bool
—intEnsure value is int
—pathEnsure value is path relative to repository root
—expiry-dateEnsure value is expiry date
—colorEnsure value shows as color
—editOpen config file in editor
—includesRespect includes when looking up values
—no-includesDon’t respect includes
—default Provide default value when no match
—show-originShow origin of each config value
—show-scopeShow scope of each config value
—helpDisplay help
ParameterDescription
Configuration scope (—local, —global, —system, etc.)
Configuration key (section.key or section.subsection.key)
Value to set
Pattern to match for —get operations
Terminal window
git config --global user.name "John Doe"
git config --global user.email "john@example.com"

Sets the user identity for all repositories on this machine.

Terminal window
git config --global user.name

Displays the globally configured user name.

Terminal window
git config --global --list

Shows all global configuration options.

Terminal window
git config --global core.editor "vim"

Configures Vim as the default Git editor.

Terminal window
git config --global core.autocrlf input

Converts CRLF to LF on commit but doesn’t convert on checkout.

Terminal window
git config --global push.default simple

Only pushes the current branch to its upstream counterpart.

Terminal window
git config --global --show-origin user.name

Shows where the user.name setting is defined.

Terminal window
git config --global --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/*

Add additional fetch refs without removing existing ones.

Terminal window
git config --global --unset core.editor

Removes the core.editor setting.

Terminal window
git config --local core.repositoryformatversion 0

Sets a local repository setting.

Terminal window
git config --global credential.helper store

Stores credentials in plain text file for future use.

Terminal window
git config --get user.email || echo "No email configured"

Retrieves email if set, or provides default message.

Terminal window
git config --global alias.co checkout
git config --global alias.br branch

Creates command aliases for shorter typing.

Terminal window
git config --global diff.tool vimdiff
git config --global merge.tool vimdiff

Sets tools for viewing differences and resolving merges.

How do I configure my Git user name and email?

Section titled “How do I configure my Git user name and email?”

To configure your Git user name and email, use:

Terminal window
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

How can I view all my Git configuration settings?

Section titled “How can I view all my Git configuration settings?”

To view all your Git configuration settings, run:

Terminal window
git config --global --list

How do I change the default Git text editor?

Section titled “How do I change the default Git text editor?”

To change the default Git text editor, execute:

Terminal window
git config --global core.editor "editor-name"

To set up a Git alias, use:

Terminal window
git config --global alias.alias-name "git command"

How do I see where a configuration value comes from?

Section titled “How do I see where a configuration value comes from?”

To see where a configuration value comes from, run:

Terminal window
git config --global --show-origin setting.name
  1. Setting up initial Git configuration with user identity
  2. Customizing Git behavior for different projects
  3. Managing credential helpers for remote authentication
  4. Creating aliases for frequently used commands
  5. Configuring diff and merge tools for development workflow
  6. Managing repository-specific settings for project requirements
  7. Setting up system-wide Git configuration for teams