How to Set Up Git Username and Email in Ubuntu

Git Config Featured

Git is a distributed version control system developed by Linus Torvalds to help build the Linux kernel. Since its initial days, Git has grown tremendously to become the most popular version control system.

Git allows multiple users to simultaneously contribute to a single project, track changes, revert to previous versions, and create branches for various project versions. This is why it is important to set up your username and email in Git so each commit can be traced back to the user.

The essence of this guide is to walk you through the basics of getting started with Git after installation, particularly setting up a username and email in Git.

Note: while we are using Ubuntu for this tutorial, the steps will apply regardless of the OS you are working with.

How to Configure a Global Git Username and Email

After installing Git, you need to set your username and email address. Git allows you to set a global username and email to be used in all your git projects or local credentials used in a specific repository.

To set your git credentials, use the git config command. Git config is a built-in tool that allows you to view and set git variables.

In Ubuntu, the git configuration variables are in the following directories:

  • /etc/gitconfig – This file stores the git configurations for all users and their repositories.
  • ~/.gitconfig – The .gitconfig file in the home directory; stores git configurations for a specific user.
  • .git/config – This stores the git configuration for the local repository.

To verify your username and email configuration, use the command:

git config --list

If you do not get any output from the command above, set your username and email.

To set the global commit username and email, enter the commands:

git config --global “Username”
git config --global

Once the commands execute successfully, verify the set variables using the command:

git config –list

After running this command, you should get an output similar to the one shown:
Git Config List

You can also edit the git config file to add the username and password. Using your favorite text editor, edit the “~/.gitconfig” file and add the username and email.

nano /home/ubuntu/.gitconfig

Add the entries as:

    name = Username
    email =

Save the file and use the git config command to verify you have added the entries successfully.

How to Configure a Local Git Username and Email

Git also allows you to configure a local username and email. You can use local credentials for a specific repository.

To do this, use the git config command without the --global flag from inside the repository directory.

For example:

Navigate to the directory you wish to use as a repo:

cd ~/workspace

Next, initialize the directory as a git repository with the command:

git init .

Inside the repository, use the commands below to set the username and email.

git config “localusername”
git config “user@ubuntu.local”

To verify the changes, use the command:

cat .git/config

The command above will navigate to the .git directory inside your local repository and show the config file contents. Git stores the configurations for a specific repo in the .git/config file.

The output for this will be:

    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    name = localusername
    email = user@ubuntu.local

To show both global and local settings, you can use the git config command. Here is an example output:

Useful git config Commands

The git config command also allows you to set up other git settings.

For example, you can set the default git editor using the command:

git config --global core.editor vim

Replace vim with the editor of your choice, such as Emacs, nano, etc.

You can also change the default name for the initial branch – set to “master” by default.

Use the command below to change the default init branch name.

git config --global init.defaultBranch initial

Similarly, replace the “initial” with the desired name for your init branch.

Check all your settings as shown in the output below:

Wrapping Up

Git is an incredible tool that is helping users maintain, contribute, and share their work with others. To be more efficient when using Git, you can also make use of Git Alias to improve your workflow, or learn how to delete a local or remote branch.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox