Git fundamentals

Configure your Git identity

Set the name and email Git records inside new commits.

8 minute lesson

~~~

Git records an author name and email inside every commit. This identifies the author in project history. It is not a login: Git never checks these values against any account, it just writes them into each commit you create.

Why does this come before your first commit? Because Git refuses to commit without an identity. On a fresh installation, git commit stops with “Please tell me who you are” and prints the exact commands to fix it.

Set them once for your user account:

git config --global user.name "Flavio Copes"
git config --global user.email "[email protected]"

Use your own name and email. The --global flag writes to a configuration file in your home directory, ~/.gitconfig, so the values apply to every repository you work on as this user. Then verify the stored values:

git config --global --get user.name
git config --global --get user.email

Each command should print back exactly what you set. Pick the email deliberately: hosting platforms such as GitHub use it to connect commits to your profile, so an email your account does not know about produces commits that look like a stranger wrote them.

A project can override the global value with local configuration. Say your employer wants work commits under a work address. Run this inside that repository, without --global:

git config user.email "[email protected]"

The value lands in that repository’s .git/config file and wins over the global one there. Run the same command with --get but without --global to inspect the value Git will use in that repository.

Configuration changes affect future commits. They do not rewrite authors stored in existing commits, so fix a wrong identity as soon as you notice it.

Exercise: create a disposable repository and run git config --show-origin --get user.email. Notice that Git shows both the value and the configuration file that supplied it. That one command settles every “which email will this commit use?” doubt.

Lesson completed

Take this course offline

Get every free book, course edition, and software download.

Get the download library →