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 BashCheck it worked:
git --versionIt 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 mainThe 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 rungit configinside 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.
The global default
Asha set
user.emailtoasha@example.comwith--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.
Which command confirms Git is installed and shows its version?
Where does git config --global user.name "Asha Rao" store the setting?
user.email is set globally to A and locally in one repository to B. Which email do commits in that repository use?
Asha runs git config user.name "Asha" inside recipe-box, with no level flag. Which level is written?
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.
