← Back to Chapters

Git Config

⚙️ Git Config

? Quick Overview

Git configuration allows you to customize how Git behaves on your system. You can define your identity, preferred editor, merge tools, and many other settings globally or per repository.

? Key Concepts

  • Git uses configuration levels: system, global, and local
  • User name and email identify commits
  • Editors and merge tools improve workflow

? Syntax / Theory

Git configurations are managed using the git config command. Values can be stored globally or locally depending on the flags used.

? Configuring Your Name and Email

? View Code Example
// Set global username for all repositories
git config --global user.name "Your Name"
// Set global email address for commits
git config --global user.email "your.email@example.com"

The --global flag applies settings to all repositories. Omitting it applies settings only to the current repository.

? Checking Your Configuration

? View Code Example
// Display all current Git configuration values
git config --list

? Editing Your Git Config File

? View Code Example
// Open global Git configuration in default editor
git config --global --edit

? Setting Default Editor

? View Code Example
// Set Visual Studio Code as the default Git editor
git config --global core.editor "code --wait"

? Setting the Default Merge Tool

? View Code Example
// Configure vimdiff as the default merge tool
git config --global merge.tool vimdiff

? Local vs Global Configurations

? View Code Example
// Set repository-specific email address
git config user.email "different.email@example.com"

? Verifying Configuration Changes

? View Code Example
// Check configured username
git config user.name
// Check configured email
git config user.email

? Live Output / Explanation

Running these commands prints the currently active configuration values, confirming whether global or local settings are applied.

? Use Cases

  • Identifying contributors in team projects
  • Using different emails for work and personal repositories
  • Improving conflict resolution with merge tools

? Tips & Best Practices

  • Always set your name and email before making commits
  • Use global config for common defaults
  • Override locally only when necessary

? Try It Yourself

  • Set your name and email using Git config
  • Check your configuration list
  • Change the default editor and test it
  • Set a local email and verify it