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.
Configure Your Author Name
Section titled “Configure Your Author Name”Run the following command and replace Your Name with the name you want to
display in your commits:
git config --global user.name "Your Name"Example:
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.
Configure Your Author Email
Section titled “Configure Your Author Email”Run the following command and replace the example address with your email:
git config --global user.email "you@example.com"Example:
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.
Set the Default Branch Name
Section titled “Set the Default Branch Name”New Git repositories require an initial branch name. You can configure Git to use
main by default:
git config --global init.defaultBranch mainAfter 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.
Review Your Git Configuration
Section titled “Review Your Git Configuration”To display the configuration values currently available to Git, run:
git config --listYou may see output similar to:
user.name=Omar Ahmeduser.email=omar@example.cominit.defaultbranch=mainTo see each value together with the configuration file from which Git loaded it, use:
git config --list --show-originThis command is especially useful when the same setting exists in more than one configuration file.
Check One Setting
Section titled “Check One Setting”You can also read one configuration value at a time:
git config --global user.namegit config --global user.emailgit config --global init.defaultBranchWhat Does --global Mean?
Section titled “What Does --global Mean?”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:
~/.gitconfigGit Configuration Levels
Section titled “Git Configuration Levels”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:
git config --local user.email "work@example.com"Local settings have priority over global settings for that repository.
Correct a Configuration Value
Section titled “Correct a Configuration Value”If you entered the wrong name or email, run the command again with the correct value:
git config --global user.name "Correct Name"git config --global user.email "correct@example.com"The new value replaces the previous global value.
Recommended First-Time Commands
Section titled “Recommended First-Time Commands”Replace the placeholders with your own information:
git config --global user.name "Your Name"git config --global user.email "you@example.com"git config --global init.defaultBranch maingit config --list --show-originCommon Mistakes
Section titled “Common Mistakes”Using a GitHub username as user.name
Section titled “Using a GitHub username as user.name”This is allowed, but it is not required. user.name represents the author name
shown in commits, not your GitHub login credentials.
Assuming the email is private
Section titled “Assuming the email is private”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.
Expecting git config to sign in to GitHub
Section titled “Expecting git config to sign in to GitHub”Author configuration and authentication are separate concepts. Authentication for
operations such as push is configured later using HTTPS credentials or SSH keys.
Forgetting quotation marks
Section titled “Forgetting quotation marks”Use quotation marks around values that contain spaces:
git config --global user.name "Omar Ahmed"Key Takeaway
Section titled “Key Takeaway”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.