27  27. Installing and Configuring Git

Before you can use Git, it has to be installed, and you have to tell it who you are. This takes about ten minutes, and you do it once per computer.

27.1 Is Git already installed?

Open your terminal (Terminal on a Mac, Git Bash on Windows) and type:

git --version

Output (your version number will be different):

git version 2.56.0

If you see a version number, Git is installed. Any reasonably recent version works for this book. On a Mac or on Windows the line may have a little extra text after the number, such as (Apple Git-...) or .windows.2.

27.2 Installing Git

Option 1 (easiest): Apple’s Command Line Tools. Type git --version in Terminal. If Git isn’t installed yet, macOS offers to install Apple’s Command Line Tools, a free package of developer tools that includes Git. Accept, wait for the download to finish, and run git --version again. (You can also start this install yourself with xcode-select --install.)

Option 2: Homebrew. If you use Homebrew (a popular “package manager” for installing developer tools on a Mac), this installs the newest version of Git:

brew install git

Apple’s Git is usually a few versions behind the newest one. That doesn’t matter for this book.

You already have Git. Git for Windows, which you installed in Getting Bash on Your Computer to get Git Bash, is Git. Open Git Bash and run git --version to check.

The installer asked several questions about Git. These four matter most:

Installer screen Recommended choice
Choosing the default editor used by Git Visual Studio Code (if it’s installed), otherwise Nano. Not Vim, the default.
Adjusting the name of the initial branch in new repositories “Override the default branch name for new repositories”, with main
Choose the default behavior of git pull Merge (the default)
Choose a credential helper Git Credential Manager (the default)

If you skipped these screens (for example, if you installed with winget, which accepts every default), just run the configuration commands below. They fix everything.

27.3 Tell Git who you are

Every commit records an author: a name and an email address. Set yours once:

git config --global user.name "Maria Lopez"
git config --global user.email "maria@example.com"

These commands print nothing when they succeed. Use your real name (or the name you want others to see), with quotes around it because it contains a space.

  • --global means “for my user account on this computer”, so the setting applies to every repository you create or copy here.
  • Use the same email as your GitHub account, so GitHub can link your commits to your profile. Anyone who can see your repository can see this email. To keep your address private, GitHub gives you a noreply address: on github.com go to Settings > Emails, turn on Keep my email addresses private, and use the address shown there. It looks like ID+USERNAME@users.noreply.github.com.

27.5 Check your settings

git config --global --list

Output:

user.name=Maria Lopez
user.email=maria@example.com
init.defaultbranch=main
core.editor=nano
pull.rebase=false

(Git shows setting names in lowercase, such as init.defaultbranch; they’re not case-sensitive.) To check a single setting, give its name:

git config user.name

Output:

Maria Lopez

If git config --global --list prints an error such as fatal: unable to read config file '/Users/maria/.gitconfig': No such file or directory, you haven’t set anything yet.

On Windows, the choices you made in the installer are stored in a different (system-wide) file, so they don’t appear in this list. To see every setting and the file it comes from, run git config --list --show-origin.

27.6 Commit messages and other Git files are plain text

Commit messages, .gitignore files, and code are all plain text. Always write them in a text editor (nano, VS Code, Notepad, TextEdit in plain-text mode), never in a word processor such as Word or Pages. See Writing to Files for the difference.

--global settings live in a plain text file in your home folder, ~/.gitconfig:

cat ~/.gitconfig

Output:

[user]
    name = Maria Lopez
    email = maria@example.com
[init]
    defaultBranch = main
[core]
    editor = nano
[pull]
    rebase = false

Git actually reads settings at three levels:

Level Applies to Stored in Set with
system every user on the computer a file in Git’s install folder (the installer)
global you, in all your repositories ~/.gitconfig git config --global ...
local one repository only .git/config inside the repository git config ... (no --global), run inside the repository

When the same setting appears at several levels, the most specific one wins: local beats global, and global beats system. For example, running git config user.email "maria@company.com" inside one work repository changes the email for that repository only.

Windows ends each line of a text file with two invisible characters (CRLF); Mac and Linux use one (LF). Git for Windows is normally set up (core.autocrlf=true) to convert between them automatically. That’s why Windows users sometimes see warnings like:

warning: in the working copy of 'README.md', LF will be replaced by CRLF the next time Git touches it

These warnings are harmless. You can ignore them.

Practice Questions

Easy

Question 1 · Write the command

Write the command that shows whether Git is installed, and which version.

git --version

It prints something like git version 2.56.0. If Git isn’t installed, you get an error instead (or, on a Mac, an offer to install the Command Line Tools).

Question 2 · Multiple choice

Sam uses Windows and installed Git for Windows in Getting Bash on Your Computer. What does he need to do to install Git?

  1. Download Git separately from Git for Windows
  2. Nothing: Git for Windows is Git (plus Git Bash)
  3. Install Homebrew and run brew install git
  4. Install the Apple Command Line Tools

b. Git for Windows installs Git together with Git Bash, so Git is already there; he can check with git --version. Options c and d are Mac methods.

Question 3 · Short answer

Why does Git need your name and email address?

Every commit records its author (name and email). Git uses your user.name and user.email settings for that, and GitHub uses the email to link your commits to your GitHub account.

Question 4 · True or false

You must run git config --global user.name "..." again in every new repository.

False. --global settings apply to all repositories for your user account on that computer. You set them once per computer.

Question 5 · Matching

Match each setting with what it controls.

Setting Controls
1. user.name A. the editor Git opens for messages
2. user.email B. what git pull does when both sides have new commits
3. init.defaultBranch C. the author name recorded in commits
4. core.editor D. the name of the first branch in new repositories
5. pull.rebase E. the author email recorded in commits

1 → C, 2 → E, 3 → D, 4 → A, 5 → B.

Question 6 · Short answer

In nano, how do you save the file and how do you exit?

Save with Ctrl+O and then Enter (to confirm the file name); exit with Ctrl+X.

Medium

Question 7 · Write the command

Write the commands Sam should run to set his name to Sam Chen, his email to his GitHub noreply address 12345678+samchen@users.noreply.github.com, and the default branch name to main.

git config --global user.name "Sam Chen"
git config --global user.email "12345678+samchen@users.noreply.github.com"
git config --global init.defaultBranch main

Question 8 · Predict the output

On a brand-new Mac account, Maria runs only these two commands:

git config --global user.name "Maria Lopez"
git config --global init.defaultBranch main

What does git config --global --list print?

user.name=Maria Lopez
init.defaultbranch=main

Only the settings she made, in the order she made them, with the setting name shown in lowercase (defaultbranch).

Question 9 · Scenario

Maria wants to make commits in public GitHub repositories without showing her personal email address. What should she do?

On github.com, go to Settings > Emails, turn on Keep my email addresses private, and copy the noreply address shown there (it looks like ID+USERNAME@users.noreply.github.com). Then set it in Git:

git config --global user.email "ID+USERNAME@users.noreply.github.com"

(using her own address). Her commits are still linked to her GitHub account.

Question 10 · Short answer

What does --global mean in git config --global ...? What happens if you run git config user.email "..." without --global inside a repository?

--global stores the setting for your user account on this computer (in ~/.gitconfig), so it applies to all your repositories. Without --global, inside a repository, the setting is stored only for that repository (in .git/config) and overrides the global value there.

Question 11 · Read the output

Maria runs git config --global --list and sees:

fatal: unable to read config file '/Users/maria/.gitconfig': No such file or directory

What does it mean, and what should she do?

The file where global settings are stored doesn’t exist yet, which means she hasn’t set any global settings. She should run the git config --global commands for user.name, user.email, init.defaultBranch, core.editor, and pull.rebase. The first one creates the file.

Question 12 · Scenario

Sam typed git commit without -m, and his terminal filled with ~ symbols. Typing doesn’t seem to work normally. What happened, how does he get out, and how can he prevent it next time?

Git opened its editor, and on his computer that’s Vim. To get out, he presses Esc, types :wq, and presses Enter. (To write a message first, he presses i, types the message, then Esc, :wq, Enter.) To prevent it, he sets an easier editor:

git config --global core.editor "nano"

or always uses git commit -m "message".

Question 13 · Short answer

Why is pull.rebase false useful even for someone who works alone?

Working alone from two computers (or editing on github.com) can still leave new commits on both sides. Without a pull setting, git pull then stops with “fatal: Need to specify how to reconcile divergent branches.” With pull.rebase false, Git merges the two sides automatically (see Cloning and Pulling).

Hard

Question 14 · Find the bug

Maria typed:

git config --global user.name Maria Lopez

There was no error, but her commits show the author as just Maria. Why? How does she fix it?

Without quotes, Bash splits the name into two separate words, so Git receives Maria as the value and Lopez as an extra, unrelated argument. Only Maria is stored. Fix it with quotes:

git config --global user.name "Maria Lopez"

Commits she makes from now on show the full name. (Existing commits keep the old name.)

Question 15 · Scenario

Sam’s commits on GitHub show the author name, but they aren’t linked to his GitHub profile (no profile picture). git config user.email prints sam@laptop.local. What’s wrong, and how does he fix it?

GitHub links a commit to an account by its email, and sam@laptop.local isn’t an address on his GitHub account. He should set an email that is on his account (or his GitHub noreply address):

git config --global user.email "12345678+samchen@users.noreply.github.com"

New commits will be linked to his profile. Commits he already made keep the old email.

Question 16 · Compare

Explain the difference between system, global, and local Git settings, and which one wins if the same setting appears in more than one.

  • System: for every user on the computer (for example, the choices made in the Git for Windows installer).
  • Global: for your user account, in all your repositories (~/.gitconfig, set with --global).
  • Local: for one repository only (.git/config, set without --global inside the repository).

The most specific level wins: local overrides global, which overrides system.

Question 17 · Short answer

If you use VS Code as Git’s editor, the setting is code --wait, not just code. What could go wrong without --wait?

Without --wait, the code command opens the file and returns immediately, so Git thinks you’ve finished editing before you’ve typed anything. For a commit, Git then finds an empty message and cancels the commit (“Aborting commit due to empty commit message”). --wait makes Git wait until you close the file’s tab in VS Code.

Question 18 · Scenario

Sam installed Git for Windows with winget, which accepts every installer default. When he runs git init in a new project, Git prints a long hint about the branch name master. Explain why, and what he should run so that this computer behaves like the rest of the class.

The installer’s default for the initial branch name is “Let Git decide”, which means master, and its default editor is Vim. Because winget skipped the installer screens, neither was changed. He should run the configuration commands from this page:

git config --global user.name "Sam Chen"
git config --global user.email "sam@example.com"
git config --global init.defaultBranch main
git config --global core.editor "nano"
git config --global pull.rebase false

(For the repository he just created, git branch -M main renames the branch to main.)

© 2025-2026 Y. Rosenthal. All rights reserved.