Hey developers!
Before contributing to a codebase, one of the first things you need to do is configure your Git username and email.
These settings act as your digital signature, ensuring your commits are properly attributed to you.
Configuring your Git username and email ensures that each commit is tracked with your name, making it easier to identify who made which changes when troubleshooting, reviewing, or even figuring out who broke production! 😂
In this step-by-step guide, you’ll learn how to configure your Git username and email both globally and for a single repository.
Let’s get started!
Steps to follow:
Run the below command:
git config --global user.name "My name"
Replace "My Name" with your username (use quotes for multi-word names)
Run the below command:
git config --global user.email "johndoe@email.com"
Replace "johndoe@email.com" with your email. Note that the quotes need to remain the same.
Run the below commands to check your git configuration:
git config --global user.name
git config --global user.email
These commands will output the username and email configured on your device, they should match the username and email you entered in the above commands.
Note: You can run these commands from anywhere in your system, they’ll apply globally to all repositories.
P.S: Don’t configure the wrong username and email to confuse the QA team 😜
That's all!
You’ve successfully set your Git username and email globally on your device and are ready to break production 😂
Steps to follow:
First, navigate to your repository:
Ex: cd ~/desktop/my-project
Note: Replace ~/desktop/my-project with the actual path to your Git repository folder.
Run the below command:
git config user.name "My Name"
Note that the command does not include the –globally flag.
Omitting the –globally flag allows you to set your username and email for a single repository. Make sure you are running the command after checking out to the repository in your terminal
Run the below command:
git config user.email "johndoe@email.com"
The same configuration works for setting up the email as well. Just omit the –globally flag and replace user.name with user.email
Run the below commands to check your git configuration for this specific repository:
git config user.name
git config user.email
These commands will output the username and email configured on your repository, they should match the username and email you entered in the above commands.
That's it!
You’ve successfully configured your Git username and email for a specific repository
With these simple steps, you can easily manage your Git settings globally within your device or for a single repository, making collaboration on projects much smoother.
Keep your settings updated to reflect the correct user information, especially if you work on multiple GitHub accounts.
Global Git configuration settings are stored in a file called .gitconfig located in your home directory. Mostly this file is located at:
Linux or macOS: ~/.gitconfig
Windows: C:\Users\YourUsername\.gitconfig
This file contains user-specific configurations like your username, email, and other Git settings that apply globally across all repositories.
Repository-specific Git settings are stored in a .git/config file within the root of the repository. These settings only apply to that particular repository.
Global configuration:
Local configuration:
The key difference is scope - global applies system-wide, local applies it within the repo. When both are set, the local configuration overrides the global configurations.
Tip: it’s a good practice to add .git/config to your .gitignore to avoid pushing local configurations.
Bonus tip: You can edit `~/.gitconfig` (global) or `.git/config` (local) directly to update configuration using the text files as well. It will also have the same impact if you forget the commands.
Still have questions?
Send an email to archana@leadwalnut.com, OR
Book a FREE consultation with an expert developer here.