Installing and Configuring Git
Install Git, learn just enough terminal to get around, and set your name, email and default branch so every commit is labeled correctly.
Welcome back!
Step 1 of 13Learn
Who made this commit?
Sam installs Git, creates a repository, and makes a first commit. Later, on GitHub, the commit shows up attributed to sam@sams-laptop.local, a made-up address the computer generated, and isn't linked to Sam's account. Nothing is broken, but every commit Sam makes is labeled with the wrong identity. Five minutes of setup prevents it.
First, install Git:
- Windows: download Git for Windows from the official site, git-scm.com. It includes Git Bash, a terminal that understands the commands used in this course.
- macOS: run
git --versionin Terminal. If Git isn't installed, macOS offers to install the developer tools that include it. Homebrew users can runbrew install git. - Linux: use your package manager, such as
sudo apt install giton Ubuntu or Debian.
Check it worked by opening a terminal and typing:
git --version
You should see something like git version 2.47.1. Any recent version works for this course. If you see "command not found," close and reopen the terminal, or check that the installer added Git to your path.
Step 2 of 13Learn
Just enough terminal
Git has graphical apps, but every tutorial, error message and Stack Overflow answer uses terminal commands, so it's worth knowing a handful. The terminal always has a current folder, and commands act on it.
pwdprints the current folder ("print working directory").lslists the files in it. In Windows Command Prompt the equivalent isdir; Git Bash and PowerShell acceptls.cd projectsmoves into theprojectsfolder;cd ..moves up one level;cd ~goes to your home folder.mkdir websitecreates a folder namedwebsite.
Git commands all start with git followed by a subcommand: git status, git commit, git log. Options start with dashes: a single dash for one-letter options (-m), two dashes for words (--global).
Two habits save a lot of confusion. First, before running a Git command, check that you're in the right folder: most "not a git repository" errors simply mean you're one folder away. Second, read the output. Git's messages are long, but they usually tell you exactly what happened and often suggest the next command.
For built-in help, git help commit opens the manual page for a command, and git commit -h prints a short summary.
Step 3 of 13Flashcards
Terminal survival kit
Tap a card to flip it.
Step 4 of 13Practice · Match the pairs
Match each command to what it does.
Tap an answer, then tap the place where it belongs (or drag it there).
- pwd
- cd ..
- mkdir notes
- git --version
- git help log
Step 5 of 13Learn
Tell Git who you are
Every commit records an author name and email. Set them once for your user account:
git config --global user.name "Sam Rivera"
git config --global user.email "sam@example.com"
The --global flag stores the setting in a file in your home folder (~/.gitconfig), so it applies to every repository you work in. Use the same email address as your GitHub account so GitHub can link your commits to your profile.
Git settings exist at three levels, and the most specific one wins:
| Level | Flag | Applies to |
|---|---|---|
| System | --system | Every user on the computer |
| Global | --global | All your repositories |
| Local | (none, run inside a repo) | Only that one repository |
The local level is useful when one computer serves two roles. If you use a work email for work projects and a personal one for everything else, set the personal one globally, then inside each work repository run git config user.email "sam@company.com" without --global.
To check what's set, run git config --list or ask for one value: git config user.email.
Step 6 of 13Practice · Diagram
Where Git settings live
Git reads all three levels; the more specific one wins when they disagree.
Sam sets a work email in one repository and a personal email globally. Which level decides the commits in that repository?
Tap the shape that answers the question, then press Check.
- Local: this repository only
Stored in
.git/config. Set withgit config user.email ...inside the repo. Wins over global.- Global: your user account
Stored in
~/.gitconfig. Set with--global. Applies to every repo you open.- System: every user on the machine
Set by installers or admins with
--system. Rarely touched.
Step 7 of 13Practice · Fill in the blanks
Fill in the blanks
To set the email used on all your commits across every repository, run: `git config user. "you@example.com"`
Step 8 of 13Learn
Three more settings worth making
Default branch name. When you create a repository, Git makes a first branch. Older versions name it master; GitHub and many teams now use main. Set your preference so new local repositories match GitHub:
git config --global init.defaultBranch main
Editor. Some commands, such as a commit without a message, open a text editor. Git's default on many systems is Vim, which confuses newcomers who can't figure out how to exit (type :q! and press Enter to quit without saving). If you use VS Code, set it instead:
git config --global core.editor "code --wait"
Line endings. Windows ends lines of text with two invisible characters (CRLF); macOS and Linux use one (LF). Mixed teams can see every line of a file marked as changed for no visible reason. On Windows, the Git installer sets core.autocrlf to true by default, which converts line endings automatically. Many projects also add a .gitattributes file to settle the question for everyone.
That's it. Git works without any other configuration, and you can always change these later.
Step 9 of 13Tap to reveal
The three settings, one command each
Default branch
git config --global init.defaultBranch mainmakes new repositories start onmain, matching GitHub.Editor
git config --global core.editor "code --wait"opens VS Code instead of Vim for messages.Line endings
On Windows,
core.autocrlf true(the installer default) converts CRLF and LF so files do not look fully changed.Check it all
git config --list --show-originprints every setting and the file it came from.
Step 10 of 13Note
Step 11 of 13Practice · Put in order
Put these first-time setup steps in a sensible order.
Drag the items, or use the arrow buttons, to put them in order.
- Open a terminal and run git --version to confirm it works
- Set user.name and user.email with --global
- Set init.defaultBranch to main
- Install Git from git-scm.com or your package manager
- Create your first repository
Step 12 of 13Practice · What would you do?
What would you do?
Sam's global email is a personal address. Sam's employer requires work commits to use sam@company.com, but only in the company's repositories. What should Sam do?
Step 13 of 13Practice · Choose one
You run git status and get "fatal: not a git repository". What is the most likely cause?
Lesson complete!