Skip to content

How to Set Git Username and Email Globally

DodaTech 2 min read

In this tutorial, you'll learn about How to Set Git Username and Email Globally. We cover key concepts, practical examples, and best practices.

The Problem

You run git commit for the first time and see:

Author identity unknown
*** Please tell me who you are.
Run
  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

Without a configured name and email, Git refuses to create commits.

Quick Fix

Step 1: Set your global username and email

Configure your identity for all repositories:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Step 2: Verify the configuration

Check that the values are stored correctly:

git config --global --list
user.name=Your Name
user.email=you@example.com

Step 3: Set different identity per repository

Navigate to a specific repo and set local overrides:

cd /path/to/project
git config user.name "Work Name"
git config user.email "work@company.com"

Verify local config:

git config --list

Local values override global ones for that repository only.

Step 4: View the config file directly

Global config is stored in ~/.gitconfig:

cat ~/.gitconfig
[user]
    name = Your Name
    email = you@example.com

You can edit this file directly with any text editor.

Step 5: Use a different email for privacy

GitHub provides a noreply email to keep your personal address private:

git config --global user.email "username@users.noreply.github.com"

Alternative Solutions

Use conditional includes for multiple identities

Automatically switch config based on directory:

git config --global includeIf.gitdir:~/work/.path ~/.gitconfig-work

Set environment variables for CI

Override Git identity in CI pipelines via environment:

export GIT_AUTHOR_NAME="CI Bot"
export GIT_AUTHOR_EMAIL="ci@company.com"

Common Mistakes to Avoid

Setting user.email globally to a private address. Your email is visible in every commit. Use a GitHub noreply address or a work alias.

Using --global when you need per-repo config. Work and personal projects may need different emails. Use git config without --global in the repo directory.

Forgetting to set user.name and email before first commit. Git refuses to create commits without this information. Configure it right after installing Git.

Pro Tips

Use includeIf for conditional config. Automatically switch Git identity based on directory location: [includeIf "gitdir:~/work/"] path = ~/.gitconfig-work.

Set git config for specific file modes. Configure core.fileMode false on Windows or network mounts to avoid spurious permission changes.

Use git config --global core.autocrlf input. Prevent line-ending issues by setting input on Linux/macOS and true on Windows.

Use environment variables in CI pipelines. Set GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL environment variables in your CI configuration to override Git identity without modifying config files.

Use git config --list --show-scope to see where each setting comes from. This shows whether user.name is set globally, locally, or system-wide, helping debug config conflicts.

Prevention

  • Set global user.name and user.email immediately after installing Git.
  • Use per-repository config for work vs personal projects.
  • Verify with git config user.name before committing to a new repository.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro