How to Set Git Username & Email Config (Global & Local)| Sabbirz | Blog

How to Set Git Username & Email Config (Global & Local)

Git Check Username password and config

Check & Set Your Git Config

🧠 Solution for My Noob and Impatient Users

If you just want the quick fix — here it is:

# Check config
git config --list

# Check your global Git config
git config --global user.name
git config --global user.email

# Set or update them
git config --global user.name "Your Name"
git config --global user.email "[email protected]"

Done ✅ — you’ve now set your Git identity globally for all projects. Now, let’s break it down properly for those who like to understand what’s really happening under the hood.


⚙️ What Git Config Actually Means

When you commit to a Git repository, Git records who made that change. It does this using two simple pieces of info:

  • user.name → your display name
  • user.email → your email address (usually the one linked with GitHub)

Every commit you make is stamped with this info — it’s your digital signature inside Git.


🔍 Step 1: Check Your Current Git Config

You can check your Git configuration in three scopes:

Global (applies to all repos)

git config --global user.name
git config --global user.email

This is stored in:

~/.gitconfig

📁 Local (specific to current repository)

If you’re inside a project folder:

git config user.name
git config user.email

This one is stored inside your project’s .git/config.

🌍 Show everything

To see all your configs (and where they come from):

git config --show-origin --list

Example output:

file:/home/sab/.gitconfig   user.name=Sabir Hasan
file:/home/sab/.gitconfig   [email protected]

✍️ Step 2: Set or Update Your GitHub Identity

If you haven’t set one yet (or want to change), use:

🌐 Set globally (for all projects)

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

📦 Set locally (for this repo only)

git config user.name "Your Work Name"
git config user.email "[email protected]"

This is great when you use different GitHub accounts — e.g., one for work, one for personal projects.


💡 Step 3: Verify Your Settings

To double-check:

git config --list

Example:

user.name=Enam Hasan
[email protected]
core.editor=vim
color.ui=auto

🧾 Pro Tip: Keep Emails Private on GitHub

If you want to hide your real email from public commits, GitHub gives you a no-reply address:

[email protected]

You can find it in your GitHub settings under Settings → Emails → “Keep my email addresses private”

Then just use it like this:

git config --global user.email "[email protected]"

This keeps your commits verified while keeping your real email hidden.


⚙️ Bonus: Manage Multiple Identities Easily

If you switch between personal and work GitHub accounts:

  1. Global config → Personal identity
    git config --global user.name "Sabir Hasan"
    git config --global user.email "[email protected]"
  2. Local config → Work identity
    git config user.name "Sabir (Work)"
    git config user.email "[email protected]"

Git will automatically use the local one when you’re inside your work repo.


🧩 Summary

Task Command Scope
Check username & email git config user.name / git config user.email Local
Check global config git config --global user.name / git config --global user.email Global
Set username & email git config --global user.name "Your Name" Global
Hide email using GitHub no-reply git config --global user.email "[email protected]" Global

🧠 Final Thoughts

Knowing how to check and set your Git config properly saves you from those “mystery commits” that show the wrong name or email. It’s one of those small hygiene habits that make your GitHub history clean, traceable, and professional.

So next time you open a new repo and push your first commit — make sure it’s signed with you.

Related posts