Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Learn the Basics  ›  Lesson

Installing Git and Telling It Who You Are

git config 12 minAfter installing Git you set your name and email, and Git reads settings from local, global and system levels, with the most specific level winning.

Installing Git and Telling It Who You Are

Before Asha records her first snapshot, Git needs two things: to exist on her computer, and to know whose name to write on every commit. Skip the second step and her commits end up signed by a guessed name like asha@Ashas-MacBook.local.

The rule

Install once, then set your name and email; the nearest setting wins.

Installing. Git is free and runs everywhere:

# macOS: installs Apple's command-line tools, which include Git
xcode-select --install
# or, with Homebrew
brew install git

# Debian or Ubuntu Linux
sudo apt install git

# Windows: download and run the Git for Windows installer,
# which also gives you Git Bash

Check it worked:

git --version

It should print a line such as git version 2.45.1. The exact number does not matter for this course, as long as it is reasonably recent. If the terminal says the command is not found, the install did not finish or the terminal needs reopening.

Configuring. Every commit is stamped with a name and email, so set them once:

git config --global user.name "Asha Rao"
git config --global user.email "asha@example.com"
git config --global init.defaultBranch main

The last line makes new repositories start on a branch called main.

Git reads settings from three levels:

  • --system: every user on this computer.
  • --global: you, in every repository. Stored in a file in your home folder, ~/.gitconfig.
  • --local: one repository only. Stored in that repository's .git/config. This is the default when you run git config inside a repository without a level flag.

When the same key is set at more than one level, the most specific one wins: local beats global, and global beats system.

The shortcut

Picture three rings: system on the outside, global in the middle, local in the centre. To find which value Git will use, start at the centre and walk outwards; the first ring that has the key wins.

Asha's work emailStep 1 of 4
  1. The global default

    Asha set user.email to asha@example.com with --global.

To check, run git config user.email inside a repository to see the value that wins, or git config --list --show-origin to see every setting and the file it came from.

Settings are not locked in: run the same command again with a new value to replace it. Changing your email later only affects future commits, though; commits already made keep the name and email they were stamped with.

The trap: setting your email with --local in the first repository and wondering why the next repository has none. Personal defaults belong in --global.

Drills

Answer fast — trust the rule.

quick drill

Which command confirms Git is installed and shows its version?

quick drill

Where does git config --global user.name "Asha Rao" store the setting?

quick drill

user.email is set globally to A and locally in one repository to B. Which email do commits in that repository use?

quick drill

Asha runs git config user.name "Asha" inside recipe-box, with no level flag. Which level is written?

quick drill

Why set user.name and user.email before the first commit?

Remember

  • Install once, then set your name and email; the nearest setting wins.
  • Local beats global beats system: start at the centre and walk out.
  • Personal defaults go in --global; per-project exceptions go in the repository.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainWhich email wins?

Asha wants her personal email on all projects except one work repository, which must use her company email. Write the commands she should run and explain which level each writes to and why the right email ends up on each commit.