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.
git config Syntax:
Section titled “git config Syntax:”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>]Options:
Section titled “Options:”| Option | Description |
|---|---|
| —local | Read/write from local .git/config file (repository-specific) |
| —global | Read/write from ~/.gitconfig or ~/.config/git/config (user-specific) |
| —system | Read/write from $(prefix)/etc/gitconfig (system-wide) |
| —worktree | Read/write from .git/config.worktree (worktree-specific) |
| —file | Use given config file instead of default |
| —blob | Read config from given blob object |
| —get | Get value (optional, defaults to listing) |
| —get-all | Get all values that match key |
| —get-regexp | Get values for all keys matching regex |
| —get-urlmatch | Get value specific to given URL |
| —replace-all | Replace all matching values with given value |
| —add | Add new value without replacing |
| —unset | Remove matching values |
| —unset-all | Remove all values |
| —rename-section | Rename section |
| —remove-section | Remove section |
| —list | List all options |
| —type | Ensure value is of given type (bool, int, string, etc.) |
| —bool | Ensure value is bool |
| —int | Ensure value is int |
| —path | Ensure value is path relative to repository root |
| —expiry-date | Ensure value is expiry date |
| —color | Ensure value shows as color |
| —edit | Open config file in editor |
| —includes | Respect includes when looking up values |
| —no-includes | Don’t respect includes |
| —default | Provide default value when no match |
| —show-origin | Show origin of each config value |
| —show-scope | Show scope of each config value |
| —help | Display help |
Parameters:
Section titled “Parameters:”| Parameter | Description |
|---|---|
| Configuration scope (—local, —global, —system, etc.) | |
| Configuration key (section.key or section.subsection.key) | |
| Value to set | |
| Pattern to match for —get operations |
git config Command Samples:
Section titled “git config Command Samples:”Set user name and email
Section titled “Set user name and email”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.
Get current configuration
Section titled “Get current configuration”git config --global user.nameDisplays the globally configured user name.
List all configurations
Section titled “List all configurations”git config --global --listShows all global configuration options.
Set default text editor
Section titled “Set default text editor”git config --global core.editor "vim"Configures Vim as the default Git editor.
Set line ending behavior
Section titled “Set line ending behavior”git config --global core.autocrlf inputConverts CRLF to LF on commit but doesn’t convert on checkout.
Set push default behavior
Section titled “Set push default behavior”git config --global push.default simpleOnly pushes the current branch to its upstream counterpart.
View config with origins
Section titled “View config with origins”git config --global --show-origin user.nameShows where the user.name setting is defined.
Add multiple values to a key
Section titled “Add multiple values to a key”git config --global --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/*Add additional fetch refs without removing existing ones.
Remove specific configuration
Section titled “Remove specific configuration”git config --global --unset core.editorRemoves the core.editor setting.
Set repository-specific config
Section titled “Set repository-specific config”git config --local core.repositoryformatversion 0Sets a local repository setting.
Configure credential helper
Section titled “Configure credential helper”git config --global credential.helper storeStores credentials in plain text file for future use.
Check if a key exists
Section titled “Check if a key exists”git config --get user.email || echo "No email configured"Retrieves email if set, or provides default message.
Create alias
Section titled “Create alias”git config --global alias.co checkoutgit config --global alias.br branchCreates command aliases for shorter typing.
Configure diff and merge tools
Section titled “Configure diff and merge tools”git config --global diff.tool vimdiffgit config --global merge.tool vimdiffSets 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:
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:
git config --global --listHow 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:
git config --global core.editor "editor-name"How can I set up a Git alias?
Section titled “How can I set up a Git alias?”To set up a Git alias, use:
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:
git config --global --show-origin setting.nameApplications of the git config command
Section titled “Applications of the git config command”- Setting up initial Git configuration with user identity
- Customizing Git behavior for different projects
- Managing credential helpers for remote authentication
- Creating aliases for frequently used commands
- Configuring diff and merge tools for development workflow
- Managing repository-specific settings for project requirements
- Setting up system-wide Git configuration for teams