Git Basics | git config
The git config command
git config is a command for changing Git settings from the command-line interface, either for the installed Git environment or for an individual repository. It can configure everything from user information to default repository behavior. The following are some commonly used configuration options.
Usage
git config user.name <name>
Sets the author name used for commits in the current repository. This setting is usually configured for the current user by adding the --global flag.
git config --global user.name <name>
Sets the author name for all commits created by the current user.
git config --global user.email <email>
Sets the author email address for all commits created by the current user.
git config --global alias <alias-name> <git-command>
Creates an alias for a Git command. This works similarly to Linux aliases.
git config --global color.ui "auto"
Enables color in the user interface of Git commands.
git config --system core.editor <editor>
Specifies the editor used when running commands such as git commit on the current machine. The <editor> argument is the command that starts the editor, such as vi.
git config --global --list
Shows the current global Git configuration.
git config --global --edit
Opens the global configuration file in a text editor so you can edit it manually.
Notes
All options are stored in plain text files, so git config is simply a convenient command-line interface for editing them. In general, Git settings are needed only when setting up a new development machine for the first time, and in practice the --global flag is used in most cases.
Git settings are stored in three files. You can use the following locations to check repository-specific, user-specific, and system-wide settings:
- <repo>/.git/config: settings for each repository.
- ~/.gitconfig: user-specific settings. Options configured with the
--globalflag are stored here. - $(prefix)/etc/gitconfig: system-wide settings.
When these settings conflict, user-specific settings take precedence over system-wide settings, and repository-specific settings take precedence over user-specific settings.
Configuration priority: repository-specific settings > user-specific settings > system-wide settings
Opening a configuration file shows content like this:
[user]
name = John Smith
email = john@example.com
[alias]
st = status
co = checkout
br = branch
up = rebase
ci = commit
[core]
editor = vim
You can edit these values manually, which has the same effect as using the git config command.
Example
After installing Git, the first thing to do is set your name and email address, and optionally define a few default preferences. Initial configuration commonly looks like this:
# Tell Git who you are
git config --global user.name "John Smith"
git config --global user.email john@example.com
# Select your favorite text editor
git config --global core.editor vim
# Add some SVN-like aliases
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.up rebase
git config --global alias.ci commit
Running these commands creates the ~/.gitconfig file shown above.