How to Set Username and Email in Git: A Step-by-Step Guide

Whether you’re contributing to an open-source project or collaborating with your team on a private repository, setting your username and email in Git is essential. These identifiers are used in every commit to associate your changes with your identity, and they’re often displayed in tools like GitHub, GitLab, and Bitbucket.

In this blog, we’ll walk through the process of configuring your Git username and email address — both globally and per project.


Why It Matters

Each Git commit includes metadata about the author. If this information isn’t properly configured, your commits might appear as coming from an “unknown” user or not be linked to your Git hosting profile. This can lead to confusion, difficulty in tracking contributions, or even problems with commit signing and permissions.


Setting Global Username and Email

The global configuration applies your username and email across all Git repositories on your machine.

Step 1: Open Your Terminal

On macOS or Linux, you can use Terminal. On Windows, you might use Git Bash, Command Prompt, or PowerShell.

Step 2: Set the Global Username

git config --global user.name "Your Full Name"

Step 3: Set the Global Email Address

git config --global user.email "yo********@ex*****.com"

These settings are saved in your Git configuration file, typically located at ~/.gitconfig.

To Confirm Your Settings:

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

Setting Username and Email Per Repository

In some cases, you may want to use different credentials for specific repositories — for example, using a work email for company projects and a personal email for open-source contributions.

Step 1: Navigate to Your Repository

cd /path/to/your/repository

Step 2: Set the Local Username

git config user.name "Your Full Name"

Step 3: Set the Local Email Address

git config user.email "yo********@ex*****.com"

This configuration will override the global settings only for the current repository.

To Confirm Local Settings:

git config user.name
git config user.email

Note: Without the --global flag, Git applies the configuration to the current repository only.


Bonus: View All Git Configurations

To see all current Git configuration values and where they are set:

git config --list --show-origin

This will display values from system, global, and local config files, helping you troubleshoot any unexpected behaviors.


Final Thoughts

Configuring your Git username and email correctly is a small but important step toward maintaining a clean and traceable development history. Whether you’re managing one repository or many, understanding how Git prioritizes local and global settings gives you the flexibility to work across different projects with ease.

If you haven’t already, take a moment to check your settings — your future self (and your teammates) will thank you!

Sharing Is Caring:

Leave a Comment