Git & GitHub ยท Chapter 3 of 42

Git Configuration

Before making commits, you should tell Git who you are. Git attaches your name and email to every commit you make, so this information should be set once on each machine you use.

Git configuration works at three levels: system (all users), global (your user account), and local (a single repository). The `git config` command lets you view and change these settings.

Syntax
git config --global user.name "Name"
git config --global user.email "email"

Setting your identity

Use `git config --global user.name "Your Name"` and `git config --global user.email "you@example.com"` to set your identity for all repositories on your machine.

Viewing configuration

Run `git config --list` to see all current settings, or `git config user.name` to check a single value. Local settings inside a repository override global ones.

Example 1 (bash)
git config --global user.name "Alex Smith"
git config --global user.email "alex@example.com"

Sets your name and email globally so every commit is attributed to you.

Example 2 (bash)
git config --list
Output
user.name=Alex Smith
user.email=alex@example.com

Lists all current Git configuration values.

Key points

  • git config sets your name and email for commits.
  • --global applies settings to all repositories on your machine.
  • Local repo config overrides global config.
  • git config --list shows all current settings.
๐Ÿ’ก Note: Use the same email you use on GitHub so your commits are linked to your GitHub profile.

๐Ÿ“ Quick Quiz

1. Which command sets your global Git username?

2. What does --global mean in git config?

3. Which command lists all Git configuration values?