Lesson 7 of 7 in Basics

Who you are

Story: Pim signs every record. A change nobody signed is a change nobody can ask about.

Every commit records who made it: a name and an email. git log shows them on each commit's Author: line, newest commit first:

commit 54b3bc26b5600961698dece5a15051ee2356296a (HEAD -> main)
Author: Sam Lee <sam@example.com>
Date:   Mon Jan 1 09:14:00 2024 +0000

    Add opening hours

commit a4b8d971a4104bc200dc7415344326f408c54d03
Author: You <you@example.com>
Date:   Mon Jan 1 09:10:00 2024 +0000

    Style the heading

git takes the name and email from its settings, which you read and change with git config.

Setting your name and email: git config --global

git config --global user.name "Sam Lee"
git config --global user.email "sam@example.com"

--global sets them for every repository on this computer, so you only do it once. Put the name in quotes when it has a space in it, and use the email you want your commits to show.

Until you set them, your commits in this Terminal carry the name You and the email you@example.com. On a new computer, git may instead refuse to commit and ask who you are.

On a real computer, --global settings go in a file in your home folder, .gitconfig. This Terminal keeps them for you out of sight, so ls -a won't show that file.

Checking what's set

git config user.name prints the name your next commit will carry, and git config user.email the email. Add --global to see what's set for every repository.

git log shows who made the commits so far. That isn't always who you are now: a commit keeps the name and email it was made with, even after you change your settings.

One repository, another identity

Leave out --global, and the setting is for the repository you're in only:

git config user.email "sam@work.example"

In that repository it wins over your global setting, so your commits there carry your work email. Every other repository still uses the global one. You need to be inside a repository to do this: elsewhere, git stops with fatal: not in a git directory.

Command What it does
git config --global user.name "<name>" Sets your name for every repository on this computer.
git config --global user.email "<email>" Sets your email for every repository on this computer.
git config user.email "<email>" Sets your email for this repository only. Here, it wins over the global one.
git config user.name Prints the name your next commit here will carry.
git config --global user.name Prints the name set for every repository.

New commands

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

Explainer: Who made this commit

project: your repo, you are here37d7cf7 Add a README37d7cf7ab89288 Add the home pageab89288a4b8d97 Style the headinga4b8d9754b3bc2 Add opening hours54b3bc2HEAD → main
The repository at the end of the Explainer.
Graph as text

project: your repo, you are here

  • HEAD → main at 54b3bc2 "Add opening hours"

Branches and tags

  • main at 54b3bc2 "Add opening hours"

Commits, newest first

  1. 54b3bc2 "Add opening hours"; parent a4b8d97; refs: HEAD → main
  2. a4b8d97 "Style the heading"; parent ab89288
  3. ab89288 "Add the home page"; parent 37d7cf7
  4. 37d7cf7 "Add a README"; no parent

Challenge 1 of 2

Story: Every agent signs the register on their first day. Sign it exactly as git knows you.

git on this computer is set up with your name and email. Make a file AUTHORS.txt that holds the name and email git puts on your commits, written as Name <email>, and commit it.

Commands 0 of Par 3

Goal

  • Met: HEAD is on branch main
  • Not met yet: Branch main is at the goal's commit
  • Not met yet: The history of main matches the goal
  • Not met yet: main has one new commit
  • Not met yet: The new commit has AUTHORS.txt, with the name and email git puts on your commits, as Name <email>

Hints

Live Graph

project: your repo, you are here37d7cf7 Add a README37d7cf7ab89288 Add the home pageab89288a4b8d97 Style the headinga4b8d97HEAD → main

Terminal

~/project (main) $