git config

Tell Git who you are

Lesson 2 of 20 · 6 min · Module 1: Your first repository

Every snapshot Git saves records who made it and when. Before your first commit, tell Git your name and email.

Start this lesson →

Free. No installation: you write and run the code in your browser, and it is checked automatically.

By the end, you’ll be able to…

  • Explain why commits record an identity
  • Set your name and email with --global
  • Read settings back

The idea

git config --global user.name "Your Name" and git config --global user.email "[email protected]" store your identity in ~/.gitconfig, for every repository on this computer. Without --global, a setting applies to the current repository only. git config user.name reads a value back, and git config --list shows every setting. For GitHub, use the email of your account, or the private no-reply address GitHub offers, so your commits link to your profile.

git config --global user.name "Ana Popescu"
git config --global user.email "[email protected]"
git config user.name
git config --list

01Every commit records a name and an email

A commit stores who made it, when, and why. Teammates read the names in the history, and GitHub uses the email to link each commit to an account.

02--global saves it once for this computer

Global settings live in ~/.gitconfig, a small text file in your home folder. Settings made without --global go into .git/config and apply to one repository only.

git config --global user.name "Ana Popescu"
git config --global user.email "[email protected]"
cat ~/.gitconfig
Output
[init]
	defaultBranch = main
[user]
	name = Ana Popescu
	email = [email protected]

03Read your settings back

git config with only a name prints its value. git config --list prints every setting: the global ones first, then the ones for this repository.

git config user.name
Output
Ana Popescu

Your turn

Set your name and email for every repository with --global (any name and email will do). Read your name back with git config user.name, then list all settings with git config --list.

What the checks look for

  • A global name is set
  • A global email is set
  • Reads the name back
  • Lists all settings
Try it in the editor →

Take this with you

Set user.name and user.email once, with --global, before your first commit.

Go a little further

Set a different email for this repository only with git config user.email "[email protected]", then compare the two with git config --list --show-origin.

Learn Git & GitHub for free

20 short lessons with real code and instant checks.

See the whole course →