Ch 01Installing Git & Local PC Environment Setup
Chapter 01 of 05·20 min

Installing Git & Local PC Environment Setup

Welcome to Workshop 02: Git & GitHub. Professional software engineering and data science require ironclad version control. Unlike cloud documents with opaque autosave, Git provides a distributed, cryptographic snapshot history of your entire project. In this chapter, you will install Git directly onto your local computer (macOS, Windows, or Linux), configure your global developer identity, and set up your command line environment.

Learning objectives
  • 01Understand the core distinction between centralized version control, local file backups, and distributed version control (Git)
  • 02Install Git on your personal computer using the recommended package manager or standalone installer for your operating system
  • 03Configure global identity keys: user.name, user.email, and init.defaultBranch main
  • 04Configure line-ending normalization (core.autocrlf) to prevent cross-platform corruption between Windows and Unix systems
  • 05Verify local installation using git --version and inspect active configuration levels with git config --list --show-origin

1.1 Why Version Control Matters: Snapshots vs File Copies

Before version control systems existed, developers and researchers tracked versions by creating endless copies of files: `model_final.py`, `model_final_v2.py`, `model_final_REAL_v3.py`. This ad-hoc approach quickly breaks down: you lose the reasoning behind changes, cannot easily collaborate, and risk overwriting teammates' work. Git was created by Linus Torvalds in 2005. It treats data like a stream of **cryptographic snapshots**. Every time you commit, Git records a snapshot of what all your files look like at that moment, producing a SHA-1/SHA-256 hash that guarantees file integrity. If a file has not changed, Git simply links to the identical file it previously stored. Crucially, **Git is completely decentralized**. Your local computer contains the entire repository history, meaning you can commit, inspect history, and branch with zero network connection.
Setup on Your Personal Computer
Because software engineering requires hands-on CLI proficiency, you will run all the commands in this workshop directly in your personal machine's Terminal (macOS/Linux) or PowerShell / Git Bash (Windows). You do not need to run an in-browser emulator.

1.2 Installing Git on macOS, Windows & Linux

Select the installation path tailored for your operating system: ### macOS Open your Terminal (`⌘ + Space`, type `Terminal`, hit Enter) and check if Apple Command Line Developer Tools are installed by running `xcode-select --install`. Alternatively, if you use Homebrew, simply run: `brew install git` ### Windows Download the official **Git for Windows** standalone installer from [git-scm.com](https://git-scm.com/download/win). When running the installer: • Select **Use Visual Studio Code as Git's default editor** (if installed) • Choose **Git from the command line and also from 3rd-party software** • Under line ending conversions, choose **Checkout Windows-style, commit Unix-style line endings** (`core.autocrlf true`) • Use the bundled **Git Bash** or Windows Terminal with PowerShell. ### Linux (Ubuntu / Debian) Open your terminal and run: `sudo apt update && sudo apt install -y git`
Terminal Command 1: Verify Git Installation

Verify that Git is accessible in your system PATH and print the installed version.

# Check the installed Git version
git --version
Execution walkthrough
  1. 1.Open your local terminal (Terminal on Mac/Linux, PowerShell or Git Bash on Windows).
  2. 2.Type 'git --version' and press Enter.
  3. 3.Confirm that the version is 2.30 or higher.
Expected output
git version 2.44.0
Edge cases

• On macOS, running git for the first time without Xcode Command Line Tools installed triggers a system modal asking you to install them. Accept and allow it to finish. • On Windows PowerShell, if the command fails, verify that C:\Program Files\Git\cmd is present in your User Environment Variables.

Why it happens: If your terminal responds with 'command not found' or ''git' is not recognized', your system has not added Git to its environment PATH or you need to restart your terminal session after installation.

1.3 Configuring Global Developer Identity

Git embeds your author identity into every single commit you create. Before creating any commits, you must tell Git who you are. This information is public and attached immutably to your repository commits. Git stores configuration at three distinct levels: 1. **System (`--system`)**: Applied system-wide to every user on the PC. 2. **Global (`--global`)**: Applied to your personal user account across all repositories (`~/.gitconfig`). 3. **Local (`--local`)**: Applied strictly to the current active repository (`.git/config`).
Match Your GitHub Email
Make sure your user.email configuration matches the verified email address on your GitHub profile. This ensures GitHub correctly attributes your commits and contributions to your profile graph.
Terminal Command 2: Setting Global User Identity

Assign your full name and public email address to all Git commits on this machine.

# Set your full legal/professional name
git config --global user.name "Your Name"

# Set your primary email (match this with your GitHub account email)
git config --global user.email "your.email@example.com"

# Set the default initial branch name to 'main'
git config --global init.defaultBranch main
Execution walkthrough
  1. 1.Replace 'Your Name' with your name and 'your.email@example.com' with the email address registered on GitHub.
  2. 2.Run each command sequentially.
  3. 3.Setting init.defaultBranch main eliminates legacy default branch warnings when initializing new repositories.
Expected output
# (No output emitted on success)
Edge cases

• If your name contains spaces, you MUST enclose it in double quotes: git config --global user.name "First Last". Failing to do so causes Git to treat the second name as an unrecognized argument.

Why it happens: In Unix and Git conventions, silence indicates success: if no error is raised, the configuration keys were written cleanly to ~/.gitconfig.

Terminal Command 3: Cross-Platform Line Endings & Inspecting Configuration

Prevent whitespace diff noise between Windows (CRLF) and Unix/macOS (LF) and verify all settings.

# On macOS / Linux:
git config --global core.autocrlf input

# On Windows (PowerShell / Command Prompt):
# git config --global core.autocrlf true

# Verify all configured settings and their file sources
git config --list --show-origin
Execution walkthrough
  1. 1.Set core.autocrlf according to your host operating system.
  2. 2.Run git config --list --show-origin to see every active setting alongside the exact file on your disk where it was loaded.
Expected output
file:/Users/you/.gitconfig	user.name=Your Name
file:/Users/you/.gitconfig	user.email=your.email@example.com
file:/Users/you/.gitconfig	init.defaultbranch=main
file:/Users/you/.gitconfig	core.autocrlf=input

Why it happens: The --show-origin flag tells you which configuration file defines each value, resolving confusion between system, global, and local repo overrides.

1.4 Authenticating to GitHub: GitHub CLI (`gh auth login`) & Personal Access Tokens (PAT)

In August 2021, GitHub permanently deprecated plain account passwords for Git operations over HTTPS to protect against credential stuffing attacks. Today, authenticating your local terminal to GitHub requires one of two modern mechanisms: 1. **The Official GitHub CLI (`gh`)**: The recommended, streamlined approach that configures your operating system's native credential helper automatically. 2. **Personal Access Tokens (PAT)**: Cryptographic API tokens generated in your GitHub account settings with explicit granular permissions. ### Installing GitHub CLI (`gh`) • **macOS**: `brew install gh` • **Windows**: `winget install --id GitHub.cli` (or download the installer from cli.github.com) • **Linux (Ubuntu/Debian)**: `sudo apt install gh` Once installed, running `gh auth login` initiates an interactive guided setup that links your terminal to your GitHub account and saves an authentication token directly into your OS Keychain or Credential Manager.
Never Share Personal Access Tokens
Personal Access Tokens (PATs) carry the same permissions as your GitHub password. Never commit a token to a repository or paste it in public forums. If accidentally exposed, revoke it immediately in GitHub Settings > Developer Settings > Personal access tokens.
Terminal Command 4: Interactive GitHub Authentication (`gh auth login`)

Authenticate your terminal to GitHub and configure Git to use GitHub CLI as a credential helper.

# Step 1: Launch interactive GitHub authentication
gh auth login

# Interactive prompts:
# ? What account do you want to log into? -> GitHub.com
# ? What is your preferred protocol for Git operations? -> HTTPS
# ? Authenticate Git with your GitHub credentials? -> Yes
# ? How would you like to authenticate GitHub CLI? -> Login with a web browser

# Step 2: Verify active authentication state
gh auth status

# Step 3: Configure Git credential helper to prevent future password prompts
gh auth setup-git
Execution walkthrough
  1. 1.Run 'gh auth login' in your terminal.
  2. 2.Select 'GitHub.com' using arrow keys and press Enter.
  3. 3.Select 'HTTPS' as your preferred protocol.
  4. 4.Choose 'Yes' when prompted to authenticate Git with your credentials.
  5. 5.Choose 'Login with a web browser', press Enter to open your browser, enter the one-time code shown in terminal, and authorize the application.
  6. 6.Run 'gh auth status' to verify your authenticated username and active token scopes.
Expected output
github.com
  ✓ Logged in to github.com account your-username (keyring)
  - Active account: true
  - Git operations protocol: https
  - Token: gho_************************************
Edge cases

• If you have a Classic Personal Access Token (PAT): When prompted 'How would you like to authenticate?', select 'Paste an authentication token' and paste your token (starts with 'ghp_'). Ensure the token has 'repo', 'read:org', and 'workflow' scopes enabled.

Why it happens: The credentials are stored in your operating system's secure credential storage (macOS Keychain, Windows Credential Manager, or Linux libsecret), meaning your raw tokens are never written to plain text configuration files.

Practice exercise

Work through the exercise before starting the chapter assignment

Exercise 1: Audit Your Local Git Configuration

basic

Open your computer's terminal and execute the commands to verify: (1) your Git version is >= 2.30, (2) your global user.name is set, (3) your global user.email is set, and (4) init.defaultBranch is set to main.

Chapter summary

Key concepts and syntax cards for review

Key concepts
  • 01Git is a distributed version control system that stores code as immutable cryptographic snapshots
  • 02Git configuration operates at three levels: System, Global (~/.gitconfig), and Local (.git/config)
  • 03Global configuration must be populated with user.name, user.email, and init.defaultBranch main before your first commit
  • 04Line-ending normalization (core.autocrlf) prevents whitespace noise across mixed operating system environments
Syntax reference
git --versionPrints the installed Git binary version to standard output
git config --global user.name '<name>'Sets the author name associated with all future commits from this user account
git config --global user.email '<email>'Sets the author email associated with all future commits from this user account
git config --global init.defaultBranch mainSets 'main' as the default branch name for newly initialized repositories
git config --list --show-originLists all active configuration keys and the exact filesystem path of their source file
gh auth loginInitiates interactive GitHub authentication via browser OAuth or Personal Access Token (PAT)
gh auth statusVerifies current authenticated GitHub account and active token scopes
gh auth setup-gitConfigures Git to use GitHub CLI as a credential helper to prevent password prompts

Knowledge check

Verify your grasp of the chapter concepts

Where does Git save settings when you pass the --global flag to git config?

Which command lists all active Git configuration settings along with their source configuration files?