Lesson Completion
Back to course

Module 02: Git Basics

Overview

This module covers the core day-to-day Git commands you will use in almost every project: status, add, commit, log, diff, restore, and .gitignore.

Learning Objectives

  • Understand the working tree, staging area, and history
  • Use git status, git add, and git commit confidently
  • Inspect history with git log
  • Review changes with git diff
  • Undo mistakes with git restore
  • Manage files with git rm and git mv
  • Ignore files safely with .gitignore
  • Amend a commit when needed

Topics Covered

2.1 Working Tree and Staging Area

  • What is the working tree?
  • What is the staging area?
  • Why Git separates them

2.2 git status

  • Reading file states
  • Untracked, modified, staged
  • Clean working tree

2.3 git add

  • Staging a file
  • Staging parts of a file
  • Best practices

2.4 git commit

  • Writing good messages
  • Commit snapshots
  • Small, focused commits

2.5 git log

  • Basic history view
  • One-line format
  • Limiting output

2.6 git diff

  • Working tree vs staging
  • Staged vs last commit
  • Reading diffs

2.7 git restore

  • Discarding changes safely
  • Restoring from staging

2.8 git rm and git mv

  • Removing tracked files
  • Renaming files properly

2.9 .gitignore

  • Ignoring build artifacts
  • Pattern basics
  • Keep repos clean

2.10 git commit --amend

  • Fixing the last commit
  • When to avoid amend

Hands-on Exercises

  1. Create a repo and make two commits.
  2. Use git diff to compare changes.
  3. Stage changes and unstage them.
  4. Ignore a temporary file with .gitignore.
  5. Amend a commit message.

Key Takeaways

  • The working tree and staging area keep commits clean.
  • status, add, and commit are the core loop.
  • Git provides safe ways to undo and inspect changes.

Additional Resources

  • Pro Git: Git Basics
  • git help for every command

Assessment

  • Quiz on file states and commands
  • Practical: stage, commit, diff, and restore

Next Module

Module 03 will cover branching and merging fundamentals.