Skip to main content

Installing Git and Configuring Your Identity

Learning Objectives

By the end of this lesson you will be able to:

  • Install Git on Windows, macOS, or Linux.
  • Verify your installation from the command line.
  • Configure your name, email, and default editor with git config.
  • Understand the three levels of Git configuration.

Installing Git

Git runs on all major operating systems. Installation methods:

OSMethodCommand / Source
WindowsInstaller packageDownload "Git for Windows" from git-scm.com; it includes Git Bash, a Unix-like terminal
macOSXcode Command Line Tools, or Homebrewxcode-select --install or brew install git
Linux (Debian/Ubuntu)Package managersudo apt update && sudo apt install git
Linux (Fedora)Package managersudo dnf install git

After installation, confirm it worked by opening a terminal and running:

git --version

This should print a version string such as git version 2.43.0. If the command is not found, the installation did not complete correctly, or your terminal's PATH environment variable does not include Git's install location; restart your terminal or reinstall.

Configuring Your Identity

Git attaches an author name and email to every commit you make. Before your first commit, set these values:

git config --global user.name "Ada Lovelace"
git config --global user.email "ada@example.com"

The --global flag applies this setting to every repository for your user account on this machine. You can check the values with:

git config --global --list

The Three Levels of Configuration

Git configuration exists at three scopes, applied in order of increasing precedence:

  1. System (--system): applies to every user on the machine. Stored in a file such as /etc/gitconfig.
  2. Global (--global): applies to all repositories for the current user. Stored in ~/.gitconfig.
  3. Local (default, no flag, or --local): applies only to the current repository. Stored in .git/config inside that repository.

A local setting overrides a global one, which overrides a system one. This is useful, for example, if you want to use your personal email for open-source projects but a work email for a specific company repository: set the global email to personal, then override it locally inside the work repository.

cd my-work-project
git config user.email "ada@company.com"

Setting a Default Editor

Some Git commands (like writing a commit message without -m) open a text editor. If you do not configure one, Git uses your system default, which on some systems is Vim, an editor with a non-obvious exit sequence for beginners. To set Nano (simpler for beginners) instead:

git config --global core.editor "nano"

To use Visual Studio Code:

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

Common Mistakes at This Stage

  • Skipping identity configuration. Git will refuse to commit or will use a generic placeholder identity, producing unclear authorship in history.
  • Using a private email unintentionally. If you push to a public host like GitHub without configuring a suitable email, your personal email may become publicly visible in commit history. GitHub offers a no-reply email alias for this reason.
  • Getting stuck in Vim. If you accidentally open Vim and need to exit without saving, press Esc, type :q!, then press Enter.

Recap

  • Install Git via your OS's standard package manager or installer.
  • Verify installation with git --version.
  • Set your name and email globally with git config --global user.name and user.email.
  • Configuration has three scopes: system, global, local, with local taking precedence.
  • Choose a default editor you are comfortable with using core.editor.

Questions

Ask the instructor about this lesson. Questions and answers are visible to every member of the course.

No questions yet.