How to Configure Git Username and E-mail address

August 23, 2023 17:36 by Jesper Nielsen • 4 minutes to read

Git is a powerful and popular version control system that allows you to track changes in your code and files, collaborating with other developers and works great with e.g., Visual Studio Code.

One of the benefits of using Git and GitHub, or similar platforms, to version your code, or use Source Control, is that you can easily integrate them with your editor of choice. For example, Visual Studio has a built-in Git support that allows you to perform common Git operations, such as staging, committing, pushing, pulling, branching, and merging, directly from the editor. You can also view the diff between versions, resolve conflicts, and access the command line if needed. This way, you can manage your code without leaving your editor, which can save you time and improve your workflow.

Note

For use with Visual Studio Code, you will have to install Git before you can use Source Control.

However, before you start using Git on your system, there are two things you must do: configure your Git username and Git e-mail address.

This is an important task, as Git uses this information to identify you as the author of your commits and to associate them with your GitHub account.

You can use the git config command to set or change your name and e-mail address for git. You can do this globally or for each project separately. Please note, the new name and e-mail will only affect the commits you make after the change. The commits you made before the change will keep the old name and e-mail.

In this blog post, we will share how to configure your Git username and e-mail address, both globally and if you should need to, adding Git username and e-mail addre for a single repository only.

How to Find and Open git-bash.exe

If you are using Windows, you may need to use a special terminal program called git-bash.exe to run Git commands. This program is part of the Git for Windows package, which you can download and install from here. Once you have installed Git for Windows, you can find the git-bash.exe file in the following location:

C:\Program Files\Git\bin\git-bash.exe (for 64-bit systems)

C:\Program Files (x86)\Git\bin\git-bash.exe (for 32-bit systems)

You can also search for git-bash.exe in the Windows Start Menu or using File Explorer. To open the git-bash.exe program, you can either double-click on it or right-click on it and select “Run as administrator”. This will open a new terminal window where you can enter Git commands.

How to Configure Git Username and e-mail address Globally

To configure your Git username and e-mail address globally, meaning that they will apply to all the repositories on your system, you need to use the following commands in your git-bash terminal:

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

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

Replace “Your Name” and “ [email protected] ” with your own name and e-mail address.

You can check if the configuration was successful by using the command git config --global --list, which will show you the global settings for your Git.

git config --global --list 

user.name=Your Name 

[email protected] 

How to Configure Git Username and e-mail Address for a Single Repository

At times, you may want to use a different username and e-mail address for a specific repository, for example, if you are working on a project for a client or a company. To do this, you need to use the same commands as before, but without the --global option. This will set the username and e-mail address only for the current repository that you are in.

For example, if you are in the directory of a project called “./my-project”, you can use the following commands:

git config user.name "Your Name" 

git config user.e-mail "[email protected]" 

Again, replace “Your Name” and “ [email protected] ” with your own name and e-mail address. You can check if the configuration was successful by using the command git config –list, which will show you the settings for the current repository.

git config --list 

user.name=Your Name 
user.e-mail= [email protected] 

The repository-specific settings are stored in the .git/config, located in the root directory of the repository.

The wrap

That’s it! This is how to configure your Git username and e-mail address, both globally and for a single repository only.

Read more about Getting Started with Git, and Git First-Time Git Setup here .

Download Git for Windows and get started gojng with the Git - Book .

Happy coding!

–Jesper