0
0
GitHow-ToBeginner · 3 min read

How to Configure Git Username and Email for Commits

Use git config --global user.name "Your Name" and git config --global user.email "you@example.com" to set your username and email globally. For a specific repository, omit --global to set them locally.
📐

Syntax

The basic syntax to configure your Git username and email is:

  • git config [--global] user.name "Your Name" sets your name.
  • git config [--global] user.email "you@example.com" sets your email.
  • The --global flag applies the setting to all repositories on your computer.
  • Omitting --global sets the configuration only for the current repository.
bash
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
💻

Example

This example shows how to set your Git username and email globally, so all your commits use this identity.

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

Common Pitfalls

Common mistakes include:

  • Not setting email and username, causing commits to have no author info.
  • Using --global when you want to set info only for one project.
  • Typos in the email or name causing confusion in commit history.
  • Forgetting to check current settings with git config --list.
bash
git config user.name "Wrong Name"
git config user.email "wrong.email@example.com"
# Correct way:
git config user.name "Correct Name"
git config user.email "correct.email@example.com"
📊

Quick Reference

CommandDescription
git config --global user.name "Your Name"Set your name globally for all repos
git config --global user.email "you@example.com"Set your email globally for all repos
git config user.name "Your Name"Set your name for current repo only
git config user.email "you@example.com"Set your email for current repo only
git config --listShow all current Git configuration settings

Key Takeaways

Always set your Git username and email to identify your commits.
Use --global to apply settings to all repositories on your machine.
Omit --global to set username and email only for the current repository.
Check your settings anytime with git config --list.
Avoid typos to keep your commit history clear and accurate.