0
0
GitHow-ToBeginner · 3 min read

How to Use git config: Syntax, Examples, and Tips

Use git config to set Git configuration options either globally or per repository. The command syntax is git config [--global] key value, where --global applies settings for your user, and without it applies settings only to the current repository.
📐

Syntax

The basic syntax of git config is:

  • git config [--global] <key> <value>: Sets a configuration value.
  • --global: Optional flag to apply the setting globally for your user.
  • <key>: The configuration name, like user.name or core.editor.
  • <value>: The value to assign to the key.
  • You can also use git config --list to see all current settings.
bash
git config [--global] <key> <value>
git config --list
💻

Example

This example shows how to set your Git user name and email globally, then check the settings.

bash
git config --global user.name "Alice Example"
git config --global user.email "alice@example.com"
git config --list
Output
user.name=Alice Example user.email=alice@example.com ...
⚠️

Common Pitfalls

Common mistakes include:

  • Forgetting --global when you want to set user info for all repos, causing settings to apply only to the current repo.
  • Using incorrect key names, which Git will accept but not apply properly.
  • Not quoting values with spaces, leading to errors or partial values.
bash
git config user.name "Alice Example"  # Wrong: missing quotes, sets only local

git config --global user.name "Alice Example"  # Correct: quotes and global
📊

Quick Reference

CommandDescription
git config --global user.name "Your Name"Set your global Git user name
git config --global user.email "you@example.com"Set your global Git email
git config user.name "Repo Name"Set user name only for current repo
git config --listShow all Git config settings
git config --global core.editor "code --wait"Set default editor globally

Key Takeaways

Use git config --global to set user info for all repositories.
Always quote values with spaces to avoid errors.
Check your settings anytime with git config --list.
Use correct key names like user.name and user.email.
Local config overrides global config for the current repository.