CH 06 / 75Part 2: Git Basics — Working Locally

Installing and Setting Up Git

What you will learn on this page

  • Install Git using the method that suits your OS
  • Set user.name and user.email
  • Make main the default branch name
  • Understand where settings are stored and how to check them
On this page12 items

This is the start of Part 2. Parts 2 through 5 cover Git operations that happen entirely inside your own PC, with no network connection. First, you’ll install Git and tell it “who is recording.”

First, check whether it’s installed#

Open a terminal and type the following command.

text4 lines
git --version

# Output (example):
# git version 2.56.0

If you see git version followed by a number, Git is already installed. The number varies with when and how it was installed, but with 2.28 or later you can try everything in this guide. If you see something like command not found, install it using one of the methods in the next section.

Installation by OS#

OSRecommended methodCommand / where to get it
WindowsGit for Windows installerDownload from git-scm.com/install/windows
Windows (alternative)wingetwinget install --id Git.Git -e --source winget
macOSXcode Command Line Toolsxcode-select --install
macOS (alternative)Homebrewbrew install git
Debian / Ubuntuaptsudo apt-get install git
Fedoradnfsudo dnf install git

Xcode Command Line Tools on macOS includes a Git provided by Apple. It’s sometimes a slightly older version, but that’s no problem while you’re learning. If you already use Homebrew, brew install git keeps you on a newer version.

Confusing screens in the Windows installer#

The Git for Windows installer has a lot of confirmation screens, but you can generally just accept all the defaults. The two that tend to cause hesitation are:

ScreenWhat to chooseWhy
Choosing the default editor used by GitAn editor you’re used to (such as VS Code)The default, Vim, leaves you stuck figuring out how to quit if you don’t know it
Adjusting the name of the initial branch in new repositoriesChoose Override the default branch name and enter mainTakes care of the “default branch name” described below right here

Installation also installs an app called Git Bash. On Windows, type the commands in this guide in Git Bash. Commands written the same way as on macOS and Linux work there as is.

Initial setup: telling Git who is recording#

As you saw in Part 1, #05, a commit includes the author’s name and email address. Git fills these in from the values you set here. If you don’t set them, your first commit will stop with Please tell me who you are., or values guessed from your PC’s name will be used without asking.

text2 lines
git config --global user.name "Taro Yamada"
git config --global user.email "[email protected]"
  • user.name: the name recorded in history. It doesn’t have to be your real name. Using plain ASCII letters avoids garbled text in any environment
  • user.email: the email address recorded in history. The value you enter here becomes readable by anyone once you publish your commits

If there’s an address you don’t want public, it’s safe to use the noreply address you noted in Part 1, #04 (Creating a GitHub Account).

--global means “apply this to my whole user account on this PC.” Once set, it’s used in every repository you create from now on.

Make main the default branch name#

text1 lines
git config --global init.defaultBranch main

As covered in Part 1, #05, a branch is a named pointer to a commit. When you create a repository, a single first branch is set up automatically. In Git as of October 2026 (2.x), that branch is named master unless you configure otherwise.

Using main is now the norm, and this guide uses main too. Git 3.0 is expected to change the default to main, but until then, this one line keeps things consistent.

Set your editor (optional)#

When you write a commit message, Git may open an editor (covered in Part 2, #09). If you use VS Code, set it like this.

text1 lines
git config --global core.editor "code --wait"

--wait tells Git to “wait until the editor tab is closed.” Without it, Git moves on before you’ve written the message. If you’re told the code command can’t be found, you can skip this setting.

Check your settings#

text6 lines
git config --global --list

# Output (example):
# user.name=Taro Yamada
# [email protected]
# init.defaultbranch=main

To see a single value, add the key name.

text4 lines
git config user.email

# Output:
# [email protected]

Where are settings stored?#

git config settings are written to plain text files. There are three levels of storage, depending on scope.

OptionScopeStored in
--systemAll users on this PCetc/gitconfig in Git’s install location
--globalAll repositories for your user.gitconfig in your home folder
--local (default)That repository only.git/config inside the repository

If the same setting exists at multiple levels, the narrower scope wins. For example, to use a different email address only in a work repository, run git config user.email inside that repository without --global.

If you lose track of which file’s value is in effect, add --show-origin to also display where each value is stored.

text1 lines
git config --list --show-origin

Create a practice folder#

In Part 2, you’ll work hands-on in a practice folder that’s fine to break. Create one under your home folder.

text2 lines
mkdir ~/git-practice
cd ~/git-practice

~ is the symbol for your home folder. On the next page, you’ll turn this folder into a repository.

FAQ#

Q. Do I need to “register an account” for Git?
A. No. Git is software that runs on your local PC, and user.name and user.email are like a signature attached to your records. They aren’t registered anywhere.

Summary#

  • How to install Git differs by OS. If git --version shows a number, you’re ready
  • On Windows, Git Bash lets the same commands as on macOS and Linux work as is
  • user.name and user.email are written into commits and readable by anyone once published
  • init.defaultBranch main makes the first branch name main
  • Settings have three levels — --system, --global and --local — and the narrowest scope wins

Next page#

07. Creating a Repository (git init) — Run git init in the practice folder you just made and watch an ordinary folder become a repository.