Configuring Git is essential to ensure your identity is properly recorded and your work is tracked accurately. Set your name, email, and other details so Git can accurately track who makes each change, which is essential for team projects and maintaining a clear project history.
Additionally, it allows users to customize their workflow, streamline common tasks, and integrate Git smoothly with other tools.
In this tutorial, you will learn to use the git config command to configure your Git installation.

Prerequisites
- Git installed (follow our guides to install Git on Windows, macOS, or Ubuntu).
- Access to the terminal/command line.
git config Syntax
The git config
command is used to set and get Git configuration variables that control aspects of Git's behavior. Use it to configure settings globally, per Git repository, or even per session.
The command syntax is:
git config [option] [<scope>] [key] [value]
Where:
[option]
- Optional parameters that specify which action to perform. The available parameters are discussed in the section below.<scope>
- An optional parameter that specifies where the configuration applies. Common scopes are:--system
- Applies to every user on the system.--global
- Applies to the current user (typically saved in ~/.gitconfig).--local
- Applies to the current repository (default if no scope is given).
[key]
- The name of the setting you want to configure, such asuser.name
orcore.editor
.[value]
- The value to assign to the specified setting, such as your name, email, or preferred text editor.
git config Parameters
git config
parameters (also called options or flags) control what action the git config
command performs. These parameters let you list, read, write, delete, or even edit configuration values, depending on your needs. With the appropriate parameters, you can fine-tune how Git behaves for a specific repository, a single user, or the entire system.
The table below lists most commonly used git config
parameters along with their explanations:
Parameter | Description |
---|---|
--list | Lists all current configuration settings. |
--get [key] | Retrieves the value of a specific configuration key. |
--get-all [key] | Retrieves all values associated with a key if it has multiple entries. |
--set [key] [value] | Sets the value for a given key, overwriting any existing value. |
--add [key] [value] | Adds a new value to a key without overwriting existing values. |
--unset [key] | Removes the specified key from the configuration. |
--unset-all [key] | Removes all values associated with a given key. |
--edit | Opens the configuration file in the default text editor for manual editing. |
--replace-all [key] [value] | Replaces all values of a key with a single new value. |
--get-regexp [pattern] | Retrieves keys and values matching a regular expression. |
--bool | Interprets the value as a boolean when reading. |
--int | Interprets the value as an integer when reading. |
--path | Interprets the value as a file path when reading. |
Note: Check out our article comparing SSH and HTTPS for Git, and decide which one to use to connect to a remote repository.
git config Levels and Files
Before diving into specific Git configurations, it's important to understand the three configuration levels Git supports and where each level's settings are stored.
You can target any of these levels with the corresponding flag to view or modify its configuration file. When Git resolves a configuration value, it checks these levels in the following order of precedence:
- Local
- Global
- System
This means a setting in your repository's .git/config will override the same setting in ~/.gitconfig, which in turn overrides the value in the system-wide gitconfig file. The sections below explain the three levels in detail.
--local
. A repository-specific configuration (the default scope when no level is given). It applies only to the current repository and is ideal for project-specific settings that should not affect other repos. The configuration file is stored in .git/config.--global
. A user-specific configuration that applies to all repositories for the current OS user. It is the best option for settings like your name, email, or default editor. The configuration file is stored in ~/.gitconfig.--system
. A system-wide configuration level that applies to every user and repository on the machine. Only administrators should modify this setting. The configuration file is located in /etc/gitconfig on macOS/Unix, or in C:\ProgramData\Git\config on Windows.
Common Git Configurations
Git offers a wide range of configuration options that help streamline workflows, establish consistency, and improve collaboration. These settings are typically stored globally or per repository and can greatly enhance your productivity.
The sections below cover some common Git configurations.
Username and Email
Your username and email uniquely identify you as the commit author. Git includes this metadata in each commit to attribute changes correctly. Proper configuration ensures that others can track who made which changes and helps platforms like GitHub link commits to your account.
The examples below show how to set your username and email:
git config --global user.name "John Doe"
git config --global user.email [email protected]
The commands produce no output if successful. Use the commands below to verify the details:
git config --list
or
git config user.name
Default Pager
The core.pager
setting controls which pager Git uses for long output (like git log
or git diff
). By default, Git pipes output through less, but you can change it to a more advanced tool or disable pagination entirely.
For example:
git config --global core.pager "less -R"
The command produces no direct output. Commands like git log
now use the specified less pager. To disable pagination entirely, enter:
git config --global core.pager ""
Default Text Editor
The core.editor
configuration determines which editor Git invokes for writing commit messages, editing merges, and more. Without this set, Git defaults to your $EDITOR
, $VISUAL
, or vi.
Use the command below:
git config --global core.editor "code --wait"
The command produces no output. If you create a commit without specifying the message with -m
, Git opens Visual Studio Code for the message. If you set it to something other than "code
", e.g., "nano", "vim
", or "subl -w
", Git will open that editor instead.
Autocorrect
The help.autocorrect
configuration automatically corrects mistyped Git commands based on a similarity threshold. For example, to set a 50 decisecond (5 second) delay before auto-execution, run:
git config --global help.autocorrect 50
After setting the autocorrect option, run a git status
command with a typo to get the following prompt:
Output Color
The color.ui
configuration controls whether Git colorizes output. Options include true
, false
, or auto
to enable richer, more readable terminal output.
For example:
git config --global color.ui auto
Commands like git status
show added lines in green and removed lines in red:
Merge
The merge.tool
configuration specifies the tool Git uses when resolving merge conflicts, such as meld
, vimdiff
, or others.
For example:
git config --global merge.tool meld
When conflicts occur, running git mergetool
opens the configured merge tool (meld
) to reconcile differences.
Alias
Aliases are shortcuts to simplify common Git commands. For instance, you can define co
to be an alias for checkout
to save keystrokes.
Use the command below:
git config --global alias.co checkout
Next time, you can run git co branch-name
performs the same as git checkout branch-name
.
Formatting
There are several settings that help control how Git formats diffs, manages line endings, signs commits, and sets defaults for new repositories. See the examples below for different configurations:
Diff tool (diff.tool)
The diff.tool
configuration selects the tool used by git difftool
, overriding merge.tool
.
For example:
git config --global diff.tool vscode
Diff commands now open VS Code's diff viewer.
Initial branch name (init.defaultBranch)
The init.defaultBranch
configuration sets the default branch name created by git init
(replaces master
).
For example:
git config --global init.defaultBranch main
Running git init
now defaults to main
instead of master
.
Commit signing (commit.gpgsign)
The commit.gpgsign
configuration automatically signs commits with GPG. Run the command below:
git config --global commit.gpgsign true
After running the command, Git signs the commits by default, and GitHub shows them as "Verified".
Line endings (core.autocrlf)
The core.autocrlf
configuration manages cross-platform line ending conversions (true
, input
, or false
).
For example:
git config --global core.autocrlf input
The command above ensures consistent LF endings on commits.
Verbose commit (commit.verbose)
The commit.verbose
configuration includes a diff of staged changes in the commit editor to aid context.
To enable the configuration, run:
git config --global commit.verbose true
Now, running git commit
adds a diff preview in the editor.
Pull behavior (pull.rebase)
The pull.rebase
configuration makes git pull
always rebase instead of merge. To enable the setting, run:
git config --global pull.rebase true
After running the above command, git pull
no longer creates merge commits during updates.
Push tracking (push.autoSetupRemote)
The push.autoSetupRemote
configuration automatically sets upstream tracking on the first push. To enable it, run:
git config --global push.autoSetupRemote true
After pushing a new branch, it is set up to track its remote counterpart.
Conclusion
This guide showed how to use the git config
command to customize and optimize your Git environment. Understanding how to manage configuration at the local, global, and system levels enables you to streamline your daily tasks and avoid needless friction.
Next, learn how to push your local repository to GitHub.