All chapters in this track
- 011. The Mental Model
- 022. Essential Setup
- 033. Core Daily Workflow
- 044. Branching
- 055. Merging & Conflict Resolution
- 066. Rebasing
- 077. Remote Repositories
- 088. Stashing
- 099. Undoing Things
- 1010. Tagging & Versioning
- 1111. Cherry-Pick
- 1212. Git Bisect & Blame
- 1313. Git Hooks
- 1414. Submodules
- 1515. Team Workflows
- 1616. Power Commands & Aliases
- 1717. Reflog: The Safety Net
- 1818. Practice Tasks
- 19Quick Reference Cheatsheet
Chapter 18 of 19
18. Practice Tasks
Work through these exercises in order. Each builds on the previous.
Exercise 1 — Staging & Committing
mkdir git-practice ; cd git-practice ; git init
echo "Hello World" > readme.txt
echo "secret=abc123" > .env
Tasks:
- Create a
.gitignorethat ignores.env - Stage only
readme.txt - Commit with message
docs: add readme - Verify
.envis untracked and not staged
Exercise 2 — Branches & Merging
# Starting from the repo above
git switch -c feature/about
echo "About page" > about.txt
git add . ; git commit -m "feat: add about page"
git switch main
echo "Main update" >> readme.txt
git add . ; git commit -m "chore: update readme"
Tasks:
- Merge
feature/aboutintomain— what type of merge is this? (3-way) - Inspect the merge commit with
git log --graph --oneline - Delete
feature/about
Exercise 3 — Rebase & Interactive Rebase
git switch -c feature/cleanup
echo "Step 1" > work.txt ; git add . ; git commit -m "WIP: step 1"
echo "Step 2" >> work.txt ; git add . ; git commit -m "WIP: step 2"
echo "Step 3" >> work.txt ; git add . ; git commit -m "feat: complete feature"
Tasks:
- Use interactive rebase to squash the three commits into one with message
feat: implement cleanup feature - Rebase
feature/cleanupontomain - Merge into
main— observe it's a fast-forward
Exercise 4 — Conflict Resolution
git switch main
git switch -c branch-a
echo "Color: Blue" > config.txt ; git add . ; git commit -m "set color blue"
git switch main
echo "Color: Red" > config.txt ; git add . ; git commit -m "set color red"
git merge branch-a
Tasks:
- Resolve the conflict, choosing "Color: Purple" as the final value
- Complete the merge with a commit message
merge: reconcile color config - Verify the file contents and history with
git log --oneline
Exercise 5 — Stash & Recover
git switch -c feature/header
echo "Header draft" > header.txt
# Don't commit yet — you need to hotfix main
Tasks:
- Stash your changes with a name
"header work in progress" - Switch to
main, create filehotfix.txt, commit it - Return to
feature/header, pop the stash - Verify
header.txtis back and unstaged
Exercise 6 — Undoing & Reflog
echo "Important code" > important.py ; git add . ; git commit -m "feat: important"
echo "Bug introduced" >> important.py ; git add . ; git commit -m "wip: bad change"
Tasks:
- Use
git reset --soft HEAD~1— observe commit is undone but changes are staged - Re-commit with a better message
- Use
git reset --hard HEAD~1to discard everything - Use
git reflogto find and recover the "feat: important" commit
Exercise 7 — Cherry-Pick
git switch -c experimental
echo "Util function" > utils.py ; git add . ; git commit -m "feat: add util function"
echo "Broken code" > bad.py ; git add . ; git commit -m "wip: broken experiment"
Tasks:
- Note the hash of the
feat: add util functioncommit - Switch to
main - Cherry-pick only the util function commit onto
main - Verify only
utils.pyappears, notbad.py
Exercise 8 — Full GitHub Flow Simulation
Simulate a complete feature cycle:
# Setup
git init shop ; cd shop
echo "# Shop" > README.md ; git add . ; git commit -m "init: project setup"
Tasks:
- Create
feature/add-cartbranch frommain - Add 3 commits simulating cart development
- Simulate a code review: use
git rebase -ito clean up commits before "PR" - Rebase onto
main(simulate others merged code while you worked) - Merge into
mainusing--no-ff(simulating PR merge) - Tag the release as
v1.0.0 - Push everything to a remote (use a local bare repo as stand-in):
git init --bare ../shop-remote.git git remote add origin ../shop-remote.git git push -u origin main git push origin --tags