Git config Command: A Complete Tutorial to Configure Git Settings

git config command

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 --list

This shows every active setting in order of priority and helps you see which level applies.

Unset a value:

git config --unset user.email

This removes a value from the current scope, and Git falls back to another level.

Edit the file directly:

git config --global --edit

This 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 vimdiff

This sets vimdiff as the merge tool is only for the active repository. Other repositories stay unchanged.

View all active settings:

git config --list

This 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.email

This 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?

Git config command is used to set and customize Git settings. These include:
  • 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?

To set your username and email globally:
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?

Run the following command: git config --list You can also specify:
  • git config --system --list
  • git config --global --list
  • git config --local --list

How to unset or remove a Git config value?

To remove a config setting:
git config --unset user.name
To remove it globally:
git config --global --unset user.email

Similar Reads

What is Version Control System? Software List Explained

One of the tools we need for software development is a Version Control System. It tracks code changes, making a…

Git Pull: How to Keep Your Code in Sync

When you work on a project with friends, one writes the intro, one adds pictures, and others handle different parts.…

Git List Branches: How to Show All Local & Remote Branches

You can use Git to show all branches or use branch-related commands to list branches and their status. This helps…

How to Switch Branches in Git: git switch vs checkout

The switch operation in Git will make it easier. Designed to simplify the process for developers, it's safer and more…

Git status Command with Examples

Git status command shows the state of files in your project. It shows files in the staged area, files not…

Git Help Command: A Complete Tutorial for Beginners

The git help command shows built-in guides for every Git command so you can check options with its usage and…

How to Delete a Remote Branch in Git

When you work with teams, you often need to remove old remote branches. To delete a remote branch in Git,…

Git Delete Branch: Remove Local and Remote Git Branches

Git helps you manage code in different branches. You can delete a branch when it’s old or not being used.…

Git Push: A Step-by-Step to Syncing Your Local Repository

The purpose of the Git Push command is to upload local repository changes to a remote repository. Pushing your committed…

Git Introduction: Git and GitHub Explained Guide

If you're diving into coding, your introduction to Git and GitHub will happen in no time. Git's your personal time…

Previous Article

HTML Breadcrumb Navigation Guide for Beginners

Next Article

Learn JSX in React: Syntax, Rules, and Examples

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *


Subscribe to Get Updates

Get the latest updates on Coding, Database, and Algorithms straight to your inbox.
No spam. Unsubscribe anytime.