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, andgit commitconfidently - Inspect history with
git log - Review changes with
git diff - Undo mistakes with
git restore - Manage files with
git rmandgit 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
- Create a repo and make two commits.
- Use
git diffto compare changes. - Stage changes and unstage them.
- Ignore a temporary file with
.gitignore. - Amend a commit message.
Key Takeaways
- The working tree and staging area keep commits clean.
status,add, andcommitare the core loop.- Git provides safe ways to undo and inspect changes.
Additional Resources
- Pro Git: Git Basics
git helpfor 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.