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.
- 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
1.2 Installing Git on macOS, Windows & Linux
Verify that Git is accessible in your system PATH and print the installed version.
# Check the installed Git version
git --version- 1.Open your local terminal (Terminal on Mac/Linux, PowerShell or Git Bash on Windows).
- 2.Type 'git --version' and press Enter.
- 3.Confirm that the version is 2.30 or higher.
git version 2.44.0
• 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
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- 1.Replace 'Your Name' with your name and 'your.email@example.com' with the email address registered on GitHub.
- 2.Run each command sequentially.
- 3.Setting init.defaultBranch main eliminates legacy default branch warnings when initializing new repositories.
# (No output emitted on success)
• 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.
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- 1.Set core.autocrlf according to your host operating system.
- 2.Run git config --list --show-origin to see every active setting alongside the exact file on your disk where it was loaded.
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)
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- 1.Run 'gh auth login' in your terminal.
- 2.Select 'GitHub.com' using arrow keys and press Enter.
- 3.Select 'HTTPS' as your preferred protocol.
- 4.Choose 'Yes' when prompted to authenticate Git with your credentials.
- 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.Run 'gh auth status' to verify your authenticated username and active token scopes.
github.com ✓ Logged in to github.com account your-username (keyring) - Active account: true - Git operations protocol: https - Token: gho_************************************
• 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
basicOpen 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
- 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
git --versionPrints the installed Git binary version to standard outputgit config --global user.name '<name>'Sets the author name associated with all future commits from this user accountgit config --global user.email '<email>'Sets the author email associated with all future commits from this user accountgit config --global init.defaultBranch mainSets 'main' as the default branch name for newly initialized repositoriesgit config --list --show-originLists all active configuration keys and the exact filesystem path of their source filegh auth loginInitiates interactive GitHub authentication via browser OAuth or Personal Access Token (PAT)gh auth statusVerifies current authenticated GitHub account and active token scopesgh auth setup-gitConfigures Git to use GitHub CLI as a credential helper to prevent password promptsKnowledge 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?