Table of Content
You can use the Git config command to set user data and control Git behavior. It saves preferences for projects and affects commits.
What is the git config Command?
Git config sets or reads Git settings. It controls how Git saves data and interacts with your system, and stores your name and email for commits.
Here is the basic command:
git config [options] <key> <value>You type the command, an option, a key, and a value. The key stands for a Git property like user.name. The value sets what Git stores for that property.
A user can set a name for commits and a path for an editor. It also changes how Git handles file endings or merges.
The Different Levels of Git Configuration
Git keeps settings at three levels and applies the last match. It checks the system level first, then the global level, and finally the local level.
System level:
It executes this for every user on the system.
git config --system user.name "Alice"It sets a name for every Git user on the system. You need admin rights to run it.
Global level:
It applies to your user across all repositories.
git config --global user.email "alice@example.com"This sets an email for every repository you use with your account.
Local level:
It works for one repository.
git config --local core.editor "nano"This sets a text editor for that repository only. It does not affect other projects.
Commands of Git config Settings
You use git config to read, set, or unset values. You also view all settings with a list command.
View configuration values:
git config --listThis shows every active setting in order of priority and helps you see which level applies.
Unset a value:
git config --unset user.emailThis removes a value from the current scope, and Git falls back to another level.
Edit the file directly:
git config --global --editThis opens the config file for editing in your default editor. You can then change values.
Override a setting for one command:
git -c user.name="Bob" commit -m "Test"This uses a different name for one commit and doesn’t change the stored setting.
Examples
Set a new global username:
git config --global user.name "Nora"This saves the username “Nora” for all repositories you use. It affects every new commit you create.
Change the merge tool for one repository:
git config --local merge.tool vimdiffThis sets vimdiff as the merge tool is only for the active repository. Other repositories stay unchanged.
View all active settings:
git config --listThis prints every active setting from the system, global, and local levels in one view. It shows which values Git uses right now.
Reset a user’s email at the local level:
git config --unset user.emailThis removes the local email so Git will use the global email for commits in this repository.
Wrapping Up
You learned how to use the Git config command and how it works at each level.
Here is a quick recap:
- The command sets user data and controls Git behavior. It also lets you view or reset values at system, global, and local levels.
FAQs
What is Git config command used for?
- User identity like user.name and user.email
- Editor preference like core.editor
- Aliases for shorter commands
How do I set username and email in Git config?
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
To set locally for a repo:
git config user.name "Repo User"
git config user.email "repo@email.com"How can I list all Git configuration settings?
- git config --system --list
- git config --global --list
- git config --local --list
How to unset or remove a Git config value?
git config --unset user.name
To remove it globally:
git config --global --unset user.emailSimilar Reads
One of the tools we need for software development is a Version Control System. It tracks code changes, making a…
When you work on a project with friends, one writes the intro, one adds pictures, and others handle different parts.…
You can use Git to show all branches or use branch-related commands to list branches and their status. This helps…
The switch operation in Git will make it easier. Designed to simplify the process for developers, it's safer and more…
Git status command shows the state of files in your project. It shows files in the staged area, files not…
The git help command shows built-in guides for every Git command so you can check options with its usage and…
When you work with teams, you often need to remove old remote branches. To delete a remote branch in Git,…
Git helps you manage code in different branches. You can delete a branch when it’s old or not being used.…
The purpose of the Git Push command is to upload local repository changes to a remote repository. Pushing your committed…
If you're diving into coding, your introduction to Git and GitHub will happen in no time. Git's your personal time…