datarekha

Install & first-time config

Install Git and set the global user identity that every commit will permanently embed.

5 min read Beginner Git Lesson 2 of 15

What you'll learn

  • How to install Git on macOS, Linux, and Windows
  • Why Git requires your name and email before you can commit
  • The difference between --system, --global, and --local config scopes

Before you start

Install Git

Pick the instructions for your platform. The goal is just to get Git on your PATH — keep this step fast.

macOS

The quickest path is Homebrew:

brew install git

No Homebrew? Run git --version in Terminal. macOS will offer to install the Xcode Command Line Tools automatically, which bundles a perfectly adequate Git.

Debian / Ubuntu Linux

sudo apt update && sudo apt install git

Windows

Download and run the installer from git-scm.com. The defaults are fine. This installs Git Bash and adds Git to your PATH.

Verify the installation

git --version
git version 2.44.0

The exact version number doesn’t matter — any recent 2.x release works for everything in these lessons.


Why Git needs your identity

Every Git commit stores two pieces of metadata that are baked into the commit hash and travel with the repository forever:

  • Author name — who wrote the change
  • Author email — how to reach them

This is not optional. Git enforces it because commit history is meant to be trustworthy and attributable. When you push to GitHub or share a repo with a team, every commit carries this identity permanently. You cannot edit it after the fact without rewriting history (which breaks other people’s clones).

Because of this, Git refuses to create a commit until these two values are set.


First-time setup

Run these three commands once, right after installing Git. Replace the placeholder values with your own.

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

What each line does:

  • user.name — the human-readable name embedded in every commit you make on this machine.
  • user.email — the email embedded in every commit. GitHub uses this to link commits to your account avatar.
  • init.defaultBranch main — makes git init create a branch named main instead of the legacy master. Most platforms default to main today; setting this avoids a warning on every new repo.

Optional: set your preferred editor

Git opens a text editor when you run git commit without a -m flag. The default is vi, which surprises many people. Override it:

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

Replace code --wait with nano, vim, emacs --wait, or whatever you prefer.


Inspect your config

After setting values, verify them:

git config --list
user.name=Ada Lovelace
user.email=ada@example.com
init.defaultbranch=main
core.editor=code --wait

To read a single key:

git config user.email
ada@example.com

Config scopes: system, global, local

Git reads config from three files and merges them at runtime. More specific always wins.

—system   /etc/gitconfig   (applies to every user on this machine)—global   ~/.gitconfig   (applies to you, across all repos)—local.git/config   (this repo only)← more specific wins
More specific scope always overrides less specific. A local config value silently wins over global or system.
ScopeFlagFile locationWhen to use
System--system/etc/gitconfig (Linux/macOS)Admins setting org-wide defaults
Global--global~/.gitconfigYour personal identity on this machine
Local--local.git/config inside a repoWork email for one specific repo

A common real-world pattern: set your personal email globally, then override it with your work email locally inside each work repo:

cd ~/work/company-project
git config --local user.email "ada@company.com"

Now commits in that repo use your work email; commits everywhere else still use your personal email.


What you can skip for now

The git config command has dozens of options (color.ui, pull.rebase, merge.tool, etc.). Ignore them until a workflow problem makes one relevant. The three commands in the “First-time setup” section above are the only ones you need before your first commit.


Quick check

0/3
Q1What happens if you create a commit without setting user.name and user.email?
Q2You set user.email globally to your personal address. Inside one work repo you run: git config --local user.email work@company.com. Which email appears on commits in that repo?
Q3A teammate clones your repo six months later. They run git log and see your email on every commit. Why is the email there even though they never set it?

Sign in to track your progress

Completed lessons, your XP, level, and streak save to your account — it's free and takes a few seconds.

Explore further

Cheat sheets

Related lessons

Skip to content