Skip to content

First-Time Git Configuration

After installing Git, you should configure the identity that Git will attach to your commits.

Every Git commit records information about its author, including a name and an email address.

You usually configure this information once for your operating-system user account.

Run the following command and replace Your Name with the name you want to display in your commits:

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

Example:

Terminal window
git config --global user.name "Omar Ahmed"

The value of user.name is the author name stored in your commits.

It does not have to be the same as your GitHub username. It is normally your real name or the professional name you want other contributors to see.

Run the following command and replace the example address with your email:

Terminal window
git config --global user.email "you@example.com"

Example:

Terminal window
git config --global user.email "omar@example.com"

Git stores this email in the commits you create.

If you want GitHub to associate your commits with your GitHub profile, use an email address that is added to and verified on your GitHub account.

New Git repositories require an initial branch name. You can configure Git to use main by default:

Terminal window
git config --global init.defaultBranch main

After setting this option, repositories created using git init will start with a branch named main.

This setting affects newly initialized repositories. It does not automatically rename branches in repositories that already exist.

To display the configuration values currently available to Git, run:

Terminal window
git config --list

You may see output similar to:

user.name=Omar Ahmed
user.email=omar@example.com
init.defaultbranch=main

To see each value together with the configuration file from which Git loaded it, use:

Terminal window
git config --list --show-origin

This command is especially useful when the same setting exists in more than one configuration file.

You can also read one configuration value at a time:

Terminal window
git config --global user.name
Terminal window
git config --global user.email
Terminal window
git config --global init.defaultBranch

The --global option saves the setting for the current operating-system user.

These settings are then used as defaults in Git repositories opened by that user.

On most systems, global Git configuration is stored in a file inside the user’s home directory, commonly named:

~/.gitconfig

Git configuration can exist at several levels:

Level Command option Applies to
System --system Every user on the computer
Global --global The current operating-system user
Local --local The current Git repository
Worktree --worktree A specific Git worktree when enabled

For beginners, --global is normally used for the default name, email, and initial branch.

A project can override a global setting using a local configuration.

For example, to use a different email in the current repository only:

Terminal window
git config --local user.email "work@example.com"

Local settings have priority over global settings for that repository.

If you entered the wrong name or email, run the command again with the correct value:

Terminal window
git config --global user.name "Correct Name"
Terminal window
git config --global user.email "correct@example.com"

The new value replaces the previous global value.

Replace the placeholders with your own information:

Terminal window
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
git config --list --show-origin

This is allowed, but it is not required. user.name represents the author name shown in commits, not your GitHub login credentials.

The configured email becomes part of your commits and may be visible in public repository history. Use GitHub’s noreply email if privacy is important.

Author configuration and authentication are separate concepts. Authentication for operations such as push is configured later using HTTPS credentials or SSH keys.

Use quotation marks around values that contain spaces:

Terminal window
git config --global user.name "Omar Ahmed"

Git needs an author name and email so it can identify who created each commit.

Use --global to configure defaults for your current operating-system user, set main as the default branch for new repositories, and review the stored values using git config --list --show-origin.

These settings identify your commits, but they do not sign you in to GitHub.