Git Install and Config

Before you can start tracking a project, Git needs to be installed and told your name and email so it can correctly label every commit you make.

Installing Git on Your System

Git is available on Windows, macOS, and Linux, and the installation method differs slightly for each. On Windows, you download and run the official installer from the Git website, which also provides Git Bash, a terminal that behaves like a Linux shell. On macOS, Git ships with the Xcode Command Line Tools, or can be installed through the Homebrew package manager. On Linux, Git is available through your distribution's package manager.

  • Windows: download the installer from git-scm.com and run it
  • macOS: run 'xcode-select --install', or 'brew install git' if you use Homebrew
  • Debian/Ubuntu: 'sudo apt update && sudo apt install git'
  • Fedora: 'sudo dnf install git'
  • Arch Linux: 'sudo pacman -S git'

Example

$ git --version
git version 2.44.0
Note: If your terminal reports 'command not found' after installing, close and reopen the terminal window so it picks up the updated system PATH.

Telling Git Who You Are

Every commit you create is stamped with an author name and email address, and Git refuses to let you commit until these are set at least once. This information is what shows up in the project history and, if you push to GitHub or GitLab, in the contribution graph and commit list.

Example

$ git config --global user.name "Ada Lovelace"
$ git config --global user.email "ada@example.com"
$ git config --global --list
user.name=Ada Lovelace
user.email=ada@example.com
Note: The --global flag applies these settings to every repository on your machine. Drop --global and run the same commands from inside a specific project folder if that one project needs a different name or email, for example a work email for a work project.

Choosing a Default Editor

Some Git commands, like writing a commit message without -m or editing history interactively, open a text editor. On many systems the default is Vim, which can be confusing if you have never used it. You can point Git at an editor you are comfortable with instead.

Example

$ git config --global core.editor "code --wait"
$ git config --global core.editor "nano"
ScopeFlagStored inApplies to
System--systemGit installation's config fileEvery user on the machine
Global--global~/.gitconfigEvery repository for your user
Local(none, run inside repo).git/configOnly the current repository
Note: Local settings override global settings, which override system settings. This lets you set sensible defaults globally and override them for one special project when needed.

Exercise: Git Install and Config

What does `git config --global user.name "Alex"` set?