Installing and Setting Up Git

Table of Contents

  1. Installing Git
  2. Check That It Works
  3. Tell Git Who You Are
  4. Sensible Defaults
  5. Where the Settings Live
  6. Terminal Recap
  7. Getting Help
  8. Try It Yourself

1. Installing Git

Install Git in the same terminal you used for Command Line Basics. Every command in this series then works exactly as written.

If you set up WSL in What Is the Command Line?, you're running real Linux, so Git is installed the Linux way. Open Ubuntu and run:

git --version

Ubuntu usually comes with Git already. If it says command not found, install it:

sudo apt update && sudo apt install git

Keep your projects in your Linux home folder (~), not under /mnt/c, as Moving Around explained — Git is much faster there.

Windows with Git Bash

If you used Git Bash instead, you already installed Git for Windows to get it, so there's nothing more to do. If you're starting fresh, download it from git-scm.com and run the installer — the defaults are fine for every question. Then use Git Bash, not PowerShell or Command Prompt, for this series.

macOS

macOS often has Git already. Open Terminal and type:

git --version

If Git isn't installed, macOS offers to install the Command Line Developer Tools, which include it. Click Install and wait a few minutes. If you use Homebrew, brew install git gets you a newer version.

Linux

Use your distribution's package manager:

# Ubuntu / Debian
sudo apt update && sudo apt install git

# Fedora
sudo dnf install git

2. Check That It Works

Close and reopen your terminal (so it picks up the new program), then run:

git --version

You should see something like:

git version 2.47.0

The exact number doesn't matter much. Anything from 2.28 or newer supports everything in this series, and most installs today are far newer than that.

3. Tell Git Who You Are

Every commit records an author. Before your first commit, tell Git your name and email:

git config --global user.name "Dara Sok"
git config --global user.email "dara@example.com"

Use your real name (or the name you want people to see), and the email you'll use for your GitHub account in chapter 8. That's how GitHub links your commits to your profile.

Privacy tip: Commit authors are public in public repositories. If you'd rather not publish your email, GitHub gives every account a private address like 12345678+dara@users.noreply.github.com. You'll find it later under Settings → Emails on GitHub, and you can change user.email to it at any time.

--global means "for every project on this computer". You only do this once.

4. Sensible Defaults

Three more settings save you trouble later:

git config --global init.defaultBranch main
git config --global pull.rebase false
git config --global core.editor "code --wait"

What they do:

  • init.defaultBranch main — new projects start on a branch called main, which is what GitHub uses too. (Older Git versions call it master; you'll still see that name in older projects.)
  • pull.rebase false — when you download changes from GitHub and they need combining with yours, Git does a normal merge. Without this, newer Git versions stop and ask you to choose. You'll see why it matters in chapter 9.
  • core.editor "code --wait" — when Git needs you to type a longer message, it opens VS Code and waits until you close the tab.

If you'd rather stay in the terminal, use nano, the editor you learned in Reading and Editing Files:

git config --global core.editor "nano"

If you skip this setting, Git uses your EDITOR environment variable (if you set EDITOR="nano" in Environment Variables and PATH, that's nano), and otherwise usually vim. If vim ever opens while you're writing a commit message, you already know the escape — but this time you want to keep what you typed, so press Esc, type :wq, and press Enter (:q! would throw the message away).

If code says command not found, see Opening Files in Your Real Editor in Reading and Editing Files. On WSL, you need VS Code's WSL extension first.

5. Where the Settings Live

Check everything you've set with:

git config --global --list
user.name=Dara Sok
user.email=dara@example.com
init.defaultbranch=main
pull.rebase=false
core.editor=code --wait

These settings are stored in a plain text file in your home folder called .gitconfig. The dot at the start means it's a hidden file — a dotfile, like the ones you met in How Computers Work. You can open it in your editor and read it. Nothing about Git is magic; it's files all the way down.

6. Terminal Recap

This series uses only a few terminal commands outside of Git itself — all from Command Line Basics. A quick reminder:

CommandWhat it does
pwdPrint the folder you're currently in
ls -aList files in the current folder, including hidden ones
cd my-siteMove into the my-site folder
cd .. / cd ~Move up one folder / go to your home folder
mkdir my-siteCreate a new folder called my-site
code .Open the current folder in VS Code

If any of these feel shaky, go back to Moving Around and Working with Files and Folders first.

One more habit: Git commands act on the folder you're in. If a command says not a git repository, you're almost always just in the wrong folder. Run pwd and check.

7. Getting Help

Every Git command has built-in help:

git help commit     # the full manual page
git commit -h       # a short summary of the options

Long output in Git (help pages, history, differences) opens in a pager — the same less viewer from Command Line Basics. Use the arrow keys or Space to scroll, and press q to quit. This trips up a lot of beginners: if your terminal seems frozen after a Git command, press q.

8. Try It Yourself

  1. Install Git for your system and run git --version.
  2. Set your name and email with git config --global.
  3. Set the three defaults: init.defaultBranch, pull.rebase, and core.editor.
  4. Read your config file. Run git config --global --list, then open the file itself. On macOS and Linux: code ~/.gitconfig. On Windows (Git Bash): the same command works.
  5. Practise the pager. Run git help git, scroll a little, then press q to get back to your terminal.

Git is installed and knows who you are. Next, let's create a project and take its first snapshot.

Buy Me a Coffee

Found this tutorial helpful? Consider buying me a coffee to support more free content!