| |

Git 1b 🧩 Installing Git

Git runs on every major operating system. The installation process differs by platform — Windows uses an installer with many options, Linux uses a package manager, and macOS ships Git with the developer tools. This chapter walks through each, plus verification, so you can confirm Git is ready before you start using it.


1. Installing Git on Windows

On Windows, the recommended way to install Git is Git for Windows — an installer that includes Git Bash, a Unix-like terminal that makes following Linux/macOS tutorials straightforward. Most Git documentation assumes a Unix-style shell, so Git Bash removes a lot of friction.

Download the installer:

Go to the official site — https://git-scm.com/download/win — and the download starts automatically. If it doesn’t, click 64-bit Git for Windows Setup (or 32-bit if your system needs it).

Run the installer:

Locate the downloaded file, double-click it, and if User Account Control prompts you, click Yes to allow the installer to make changes.

Walk through the wizard:

The installer asks a series of configuration questions. Most defaults are fine, but a few matter.

ScreenRecommended choiceWhy
LicenseAccept GNU GPLRequired to proceed
DestinationDefault pathAny location works
ComponentsInclude “Git Bash Here” and “Git GUI Here”Adds right-click context menu
Start Menu folderDefaultCosmetic
PATH environmentGit from the command line and also from 3rd-party softwareGit works everywhere
SSH executableUse bundled OpenSSHSimplest, safest
HTTPS backendUse the OpenSSL libraryPreferred default
Line endingsCheckout Windows-style, commit Unix-styleBest for cross-platform work
TerminalUse MinTTYBetter than the default console
git pull behaviorDefault (fast-forward or merge)Standard behavior
Credential helperGit Credential Manager CoreSaves credentials securely
Extra optionsEnable file system cachingFaster performance

Two of these are worth highlighting:

PATH environment. The recommended option — Git from the command line and also from 3rd-party software — puts Git on your system PATH. That means git works in Command Prompt, PowerShell, and Git Bash. The alternative — Use Git and optional Unix tools from the Command Prompt — can override Windows tools like find and sort, which usually causes more problems than it solves.

Line endings. Windows uses CRLF (\r\n); Linux and macOS use LF (\n). The recommended option — Checkout Windows-style, commit Unix-style — converts automatically: files are stored as LF in the repository, but checked out as CRLF on Windows. This avoids a whole class of “every line changed” diffs when collaborating across platforms.

Complete the installation:

When the wizard finishes, you can check Launch Git Bash and View Release Notes. Click Finish.

Verify:

Open Command Prompt or PowerShell and run:

git --version

You should see the installed version. Right-click on any folder and check for Git Bash Here and Git GUI Here in the context menu. Clicking Git Bash Here opens a Unix-style terminal in that directory.

Why Git Bash matters: Most Git tutorials, examples, and Stack Overflow answers use Unix-style commands — ls, cd, touch, rm. Git Bash gives you those commands on Windows, so you can copy-paste examples and they just work.


2. Installing Git on Linux

On Linux, install Git through your distribution’s package manager. It’s the easiest and most reliable path — no manual downloads, automatic updates.

Update the package lists first. This refreshes the package manager’s index so it sees the latest versions.

# Debian / Ubuntu / Mint
sudo apt update

# Fedora / CentOS / RHEL (modern)
sudo dnf check-update

# CentOS / RHEL (older)
sudo yum check-update

# Arch Linux
sudo pacman -Sy

Install Git with your distribution’s package manager:

DistributionCommand
Debian / Ubuntu / Mintsudo apt install git
Fedorasudo dnf install git
CentOS / RHEL (older)sudo yum install git
Arch Linuxsudo pacman -S git
openSUSEsudo zypper install git

Verification:

Open a terminal and run:

git --version

You should see output like git version 2.43.0 — the exact number depends on your distribution.

Why package managers are the right path on Linux: They handle dependencies, security updates, and version management. Downloading Git manually on Linux is unnecessary and risks conflicting with the system’s package ecosystem.


3. Installing Git on macOS

macOS has two paths — the easiest is built right in.

Option 1 — Xcode Command Line Tools (recommended):

Open Terminal and type:

git --version

If Git isn’t installed, macOS prompts you to install the Xcode Command Line Tools, which include Git. Click Install, accept the license, and wait. When the installation completes, git --version shows the version.

Option 2 — Homebrew:

If you prefer the latest version over Apple’s slightly older one:

brew install git

Homebrew keeps Git up to date independently of macOS.

Verify:

git --version

4. Verifying Git Works

After installing on any platform, the verification step is the same.

git --version

You should see a version string. If instead you see command not found or 'git' is not recognized, Git isn’t on your PATH — revisit the installation, particularly the PATH setting on Windows.

A second check — see Git’s help:

git --help

This opens the Git manual, confirming the installation is complete and functional.


5. Configuring Git for the First Time

Installation isn’t complete without configuration. Git records an author name and email with every commit — these are required.

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

The --global flag applies these settings to every repository on your machine. Use --local inside a specific project to override them.

Verify the configuration:

git config --global --list

This lists every global setting. You should see your name and email.

Optional but useful settings:

# Default branch name for new repositories
git config --global init.defaultBranch main

# Default editor for commit messages
git config --global core.editor "nano"

# Better diff output with color
git config --global color.ui auto

# Line ending handling (Windows only)
git config --global core.autocrlf true

Each setting stores in ~/.gitconfig — a plain text file you can edit directly if you prefer.

Why this matters now: Git will refuse to commit without an author name and email. Configuring them at install time prevents the first failed commit.


Complete Example Session

# ============================================
# PART 1: CHECK IF GIT IS INSTALLED
# ============================================

git --version
# [ git version 2.43.0 ]  (or similar)

# ============================================
# PART 2: INSTALL ON DEBIAN/UBUNTU
# ============================================

sudo apt update
sudo apt install git

# ============================================
# PART 3: INSTALL ON FEDORA
# ============================================

sudo dnf install git

# ============================================
# PART 4: INSTALL ON ARCH
# ============================================

sudo pacman -S git

# ============================================
# PART 5: INSTALL ON MACOS (via Homebrew)
# ============================================

brew install git

# ============================================
# PART 6: VERIFY
# ============================================

git --version
# [ git version 2.43.0 ]

# ============================================
# PART 7: FIRST-TIME CONFIG
# ============================================

git config --global user.name "Kronos"
git config --global user.email "kronos@example.com"

# ============================================
# PART 8: DEFAULT BRANCH NAME
# ============================================

git config --global init.defaultBranch main

# ============================================
# PART 9: VERIFY CONFIG
# ============================================

git config --global --list
# [ user.name=Kronos ]
# [ user.email=kronos@example.com ]
# [ init.defaultbranch=main ]

# ============================================
# PART 10: WHERE CONFIG LIVES
# ============================================

cat ~/.gitconfig
# [ [user] ]
# [     name = Kronos ]
# [     email = kronos@example.com ]
# [ [init] ]
# [     defaultBranch = main ]

# ============================================
# PART 11: OPEN HELP
# ============================================

git --help
# (opens the manual)

Quick Reference

Install Commands

PlatformCommand
WindowsDownload from git-scm.com/download/win
Debian / Ubuntusudo apt install git
Fedorasudo dnf install git
CentOS / RHELsudo yum install git
Archsudo pacman -S git
openSUSEsudo zypper install git
macOSbrew install git or Xcode tools

First-Time Config

SettingCommand
Namegit config --global user.name "Your Name"
Emailgit config --global user.email "you@example.com"
Default branchgit config --global init.defaultBranch main
Editorgit config --global core.editor "nano"
Colorgit config --global color.ui auto
Line endings (Win)git config --global core.autocrlf true

Verification

CommandPurpose
git --versionConfirm install
git --helpOpen manual
git config --global --listShow all global settings
cat ~/.gitconfigView raw config file

Windows Installer — Key Choices

ScreenRecommended
PATHGit from the command line and 3rd-party software
SSHUse bundled OpenSSH
HTTPSUse the OpenSSL library
Line endingsCheckout Windows-style, commit Unix-style
TerminalMinTTY
Credential helperGit Credential Manager Core
ExtraEnable file system caching

Config Scope

FlagApplies to
--systemAll users on machine
--globalCurrent user
--localCurrent repository only

Best Practices

Do This:

# Verify after every install
git --version                             # ✅

# Configure name and email immediately
git config --global user.name "Your Name"
git config --global user.email "you@example.com"   # ✅

# Set default branch name
git config --global init.defaultBranch main        # ✅

# Use package managers on Linux/macOS
sudo apt install git                      # ✅
brew install git                          # ✅

# On Windows, use Git Bash for Unix-style commands
# (right-click folder → Git Bash Here)   # ✅

Don’t Do This:

# Don't skip the user.name and user.email config
# Git will refuse to commit                      # ❌

# Don't use "Use Git and optional Unix tools from the Command Prompt"
# It overrides Windows tools                     # ❌

# Don't use the wrong line endings setting
# Expecting no CRLF conversion breaks diffs     # ❌

# Don't install manually on Linux
# Use the package manager                       # ❌

# Don't forget --global unless you want repo-specific config
git config user.name "Name"                     # ⚠️  local only

# Don't hardcode an editor you don't have
git config --global core.editor "code --wait"   # ⚠️  only if installed

Common Pitfalls

PitfallProblemSolution
git: command not foundNot on PATHReinstall with PATH option, reopen terminal
Commit rejectedNo name/emailSet user.name and user.email
Wrong line endingsDiffs show every line changedConfigure core.autocrlf
Wrong editor opensDefault editorSet core.editor
Old version in package managerMissing featuresUse official installer or Homebrew
Two Git installsConflicting versionsUninstall one

Real-World Examples

1. Verify Git is installed

git --version

Prints the version — confirms Git is available.

2. Install on Ubuntu

sudo apt update
sudo apt install git

Updates package lists, then installs Git.

3. Install on Fedora

sudo dnf install git

The modern Red Hat-based way.

4. Install on Arch

sudo pacman -S git

Arch’s package manager.

5. Install on macOS

brew install git

Latest version via Homebrew.

6. First-time config

git config --global user.name "Kronos"
git config --global user.email "kronos@example.com"

Required before the first commit.

7. Set default branch

git config --global init.defaultBranch main

New repositories start on main, not master.

8. Set editor

git config --global core.editor "nano"

Used for commit messages.

9. View config

git config --global --list

Shows all global settings.

10. Edit config file directly

nano ~/.gitconfig

Every git config --global setting lives here.


Visual: Install Paths by Platform

┌──────────────────────────────────────────────┐
│  Windows                                     │
│                                              │
│  git-scm.com/download/win                    │
│       │                                      │
│       ▼                                      │
│  Installer wizard                            │
│       │                                      │
│       ▼                                      │
│  Git + Git Bash + Git GUI                    │
│                                              │
└──────────────────────────────────────────────┘

┌──────────────────────────────────────────────┐
│  Linux                                       │
│                                              │
│  Package manager                             │
│       │                                      │
│       ▼                                      │
│  apt / dnf / pacman / zypper                 │
│       │                                      │
│       ▼                                      │
│  Git                                         │
│                                              │
└──────────────────────────────────────────────┘

┌──────────────────────────────────────────────┐
│  macOS                                       │
│                                              │
│  Option 1: Xcode Command Line Tools          │
│  Option 2: Homebrew                          │
│       │                                      │
│       ▼                                      │
│  Git                                         │
│                                              │
└──────────────────────────────────────────────┘

Visual: Config Scope

┌──────────────────────────────────────────────┐
│  --system                                    │
│                                              │
│  /etc/gitconfig                              │
│  All users on this machine                   │
│                                              │
└─────────────────┬────────────────────────────┘
                  │
                  ▼
┌──────────────────────────────────────────────┐
│  --global                                    │
│                                              │
│  ~/.gitconfig                                │
│  This user, all repositories                 │
│                                              │
└─────────────────┬────────────────────────────┘
                  │
                  ▼
┌──────────────────────────────────────────────┐
│  --local                                     │
│                                              │
│  .git/config                                 │
│  This repository only                        │
│                                              │
└──────────────────────────────────────────────┘

Precedence: local → global → system

Visual: Line Endings

┌──────────────────────────────────────────────┐
│  Windows                                     │
│  CRLF  (\r\n)                                │
│                                              │
│  hello\r\n                                   │
│                                              │
└──────────────────────────────────────────────┘

┌──────────────────────────────────────────────┐
│  Linux / macOS                               │
│  LF  (\n)                                    │
│                                              │
│  hello\n                                     │
│                                              │
└──────────────────────────────────────────────┘

┌──────────────────────────────────────────────┐
│  Recommended setting on Windows:             │
│                                              │
│  core.autocrlf = true                        │
│                                              │
│  Checkout: CRLF                              │
│  Commit:   LF                                │
│                                              │
│  Result: cross-platform diffs stay clean     │
│                                              │
└──────────────────────────────────────────────┘

Summary

TaskCommand / Action
Windows installGit for Windows installer
Linux installsudo apt install git (or dnf/pacman)
macOS installXcode tools or brew install git
Verifygit --version
Config namegit config --global user.name "Name"
Config emailgit config --global user.email "you@x.com"
Default branchgit config --global init.defaultBranch main
Default editorgit config --global core.editor "nano"
View configgit config --global --list
Config file~/.gitconfig

Key takeaways:

  • Git for Windows includes Git Bash — a Unix-style terminal that makes tutorials work
  • On Windows, choose “Git from the command line and also from 3rd-party software” for PATH
  • On Windows, use “Checkout Windows-style, commit Unix-style” for line endings
  • On Linux, install through the package manager — never download manually
  • On macOS, Git comes with Xcode Command Line Tools, or use Homebrew
  • Verify with git --version after every install
  • Configure name and email before your first commit — Git requires them
  • Set init.defaultBranch main to avoid master on new repositories
  • Settings live in ~/.gitconfig — editable directly
  • Config scope: system → global → local, with local winning

Remember: Installing Git is straightforward on every platform, but two things matter most: the PATH option on Windows (so git works everywhere) and the first-time config (name and email). Set those, verify with git --version, and you’re ready to start.


Stop using slow, ad-bloated tool sites! 🤮

🔎 Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)

⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free

🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!