Installing and configuring Git
Overview
Before your first commit, you need Git installed and a few settings in place — most importantly your name and email, because Git writes them into every commit. This takes five minutes and you’ll only do it once per computer.
Installing Git
Windows
Download Git for Windows from git-scm.com. The installer asks many questions; the defaults are good. Two worth knowing:
- Default editor: choose one you know (VS Code, Notepad++ or Nano) rather than the default Vim if you’ve never used Vim.
- Line endings: “Checkout Windows-style, commit Unix-style line endings” (the default) is right for most people.
It installs Git Bash, a terminal that understands the same commands as macOS and Linux. Use it for this course — every example will work as written. Alternatively, winget install --id Git.Git -e installs it from the command line.
macOS
Open Terminal and run git --version. If Git isn’t installed, macOS offers to install the Xcode Command Line Tools, which include it. For a more up-to-date version, use Homebrew: brew install git.
Linux
Use your distribution’s package manager:
sudo apt install git # Debian, Ubuntu
sudo dnf install git # Fedora
sudo pacman -S git # ArchLong-term-support distributions sometimes ship an older Git. Everything in this course works on Git 2.30 or newer; if yours is older, your distribution usually has a way to get a newer one (Ubuntu’s git-core PPA, for example).
Check it worked
git --version
# git version 2.56.1Telling Git who you are
Every commit records an author name and email. Set them globally — for every repository on this computer:
git config --global user.name "Asha Rao"
git config --global user.email "asha@example.com"Use the email address you’ll use for your GitHub account, so GitHub can link your commits to your profile. If you’d rather keep your address private, GitHub gives you a noreply address (in Settings → Emails) that you can use here instead.
If you skip this step, Git refuses to commit and tells you to set them — or guesses from your computer’s username, which looks unprofessional in a shared history.
Recommended settings
# New repositories start on a branch called main (instead of master)
git config --global init.defaultBranch main
# Your editor, used for commit messages and interactive commands
git config --global core.editor "code --wait" # VS Code
# git config --global core.editor "nano" # or a simple terminal editor
# Coloured output (on by default in modern Git, but harmless to set)
git config --global color.ui auto
# The first git push of a new branch links it to the same-named branch on GitHub
git config --global push.autoSetupRemote trueA few notes:
init.defaultBranch main: GitHub, GitLab and most teams usemain. Git 3.0 will makemainthe default too; until then, this setting avoids a confusing hint every time you rungit init.core.editor: the--waitflag matters for graphical editors — it makes Git wait until you close the file before continuing.push.autoSetupRemote(Git 2.37+): without it, the first push of every new branch fails with a message asking you to rungit push --set-upstream origin <branch>. With it, a plaingit pushjust works. You’ll see why in Pushing and pulling.
You’ll also meet a setting for git pull later: when your branch and GitHub’s have both moved on, modern Git stops and asks whether to merge or rebase. Pushing and pulling explains the choice, so leave it until then.
Where settings live
Git reads settings from three levels. When the same setting appears at more than one, the most specific wins: local beats global, which beats system.
This lets you have a personal email globally but a work email in work repositories:
cd ~/work/billing-service
git config user.email "asha.rao@company.example" # local: this repository onlyTo see what’s in effect and where each value came from:
git config --list --show-origin
git config user.email # the value that applies here
git config --global --edit # open your global config file in your editorThe global file is plain text, usually ~/.gitconfig:
[user]
name = Asha Rao
email = asha@example.com
[init]
defaultBranch = main
[push]
autoSetupRemote = trueLine endings (Windows users, read this)
Windows ends lines with two characters (CRLF); macOS and Linux use one (LF). If team members mix them, every line of a file can appear changed. Git for Windows sets core.autocrlf true by default, which converts automatically. For team projects, a .gitattributes file in the repository is even better, because it applies to everyone regardless of their settings:
* text=autoGetting help
git help config # the full manual page for a command
git config -h # a short summary of optionsThe manual pages are also online at git-scm.com/docs. The free book Pro Git on the same site is an excellent reference.
Check: run
git config user.nameandgit config user.email. If both print what you expect, you’re ready for your first repository.
Configure Git like a professional
Set up your global Git configuration: your name and email, main as the default branch for new repositories, a sensible editor, colour output, and a first git push of a new branch that sets up tracking automatically. Then add a repository-specific override: inside a new work-project repository, use a different email for that project only. Finish by listing your settings with the file each one comes from.
# 1. Who you are (use your own name and email)
# 2. Default branch for new repositories
# 3. Editor and colour
# 4. Let the first push of a new branch set up tracking automatically
# 5. A project that uses your work email
mkdir work-project && cd work-project
git init
# 6. Show every setting and where it comes from# 1. Who you are (use your own name and email)
git config --global user.name "Asha Rao"
git config --global user.email "asha@example.com"
# 2. Default branch for new repositories
git config --global init.defaultBranch main
# 3. Editor and colour (pick one editor line)
git config --global core.editor "code --wait" # VS Code
# git config --global core.editor "nano" # simple terminal editor
git config --global color.ui auto
# 4. Let the first push of a new branch set up tracking automatically
git config --global push.autoSetupRemote true
# 5. A project that uses your work email
mkdir work-project && cd work-project
git init
git config user.email "asha.rao@company.example" # --local is the default
# 6. Show every setting and where it comes from
git config --list --show-origin
git config user.email # → asha.rao@company.example (local wins)
git config --global user.email # → asha@example.comSummary
- Install Git from git-scm.com (Windows), Xcode Command Line Tools or Homebrew (macOS), or your package manager (Linux).
- Set
user.nameanduser.emailbefore your first commit — they are written into every commit you make. git config --global init.defaultBranch mainmakes new repositories start onmain.- Settings live at three levels — system, global (you) and local (one repository) — and the most specific wins.
git config --list --show-originshows every setting and the file it came from.