Chapter 53: Git Exercises

Git Exercises

You already know a lot of theory, commands, concepts, workflows, safety nets, advanced tricks… But knowing is not the same as being able to do it fluently under pressure.

Git is a muscle memory skill — like riding a bicycle or touch-typing. You only truly learn it when you repeat the same motions 50–100 times in slightly different situations until they become automatic.

So today we are going to do structured, progressive, realistic Git exercises — like a real bootcamp class.

I will give you 10 carefully sequenced exercises that cover 95% of daily Git usage + the most common “oh no” moments.

Do them in order. Try each one without looking back at previous explanations first — force your brain to remember. Only check if you get stuck.

All exercises can be done in one single folder — no need to create new repos every time.

Preparation (do this once)

Bash

Now — let’s start.

Exercise 1 – Basic commit cycle (foundation)

Goal: Muscle memory for everyday add → commit → status → log

  1. Create file notes.txt with content:
    text
  2. git status — see it red (untracked)
  3. Stage it → git add notes.txt
  4. git status — see it green
  5. Commit → git commit -m “Add initial learning notes”
  6. git lg or git log –oneline — see your first commit
  7. Add one more line to notes.txt:
    text
  8. Repeat: status → add → commit → log

Goal achieved when: You can do this flow without thinking — 10 seconds max.

Exercise 2 – Oops – forgot to add a file (amend)

  1. Create todo.txt with one line: “Buy milk”

  2. Commit: git add todo.txt && git commit -m “Add todo list”

  3. Realize you forgot “Call mom” — add it to todo.txt

  4. Stage the change → git add todo.txt

  5. Amend the previous commit:

    Bash
  6. git lg — see only one commit, but updated content

Goal: Understand amend rewrites last commit (new hash, same parent)

Exercise 3 – Create branch, work, merge back (GitHub Flow style)

  1. Create branch: git switch -c feature/add-login
  2. Edit notes.txt — add line “- Login system”
  3. Commit 2–3 times with different small messages
  4. Switch back: git switch main
  5. Merge: git merge feature/add-login
  6. Delete branch: git branch -d feature/add-login
  7. git lg — see fast-forward merge (clean line)

Goal: Feel safe parallel work + merge

Exercise 4 – Merge conflict (the emotional one)

  1. On main: edit line 3 of notes.txt to “- Branching is easy”

  2. Commit: git commit -am “Update branching note”

  3. Switch to new branch: git switch -c feature/improve-notes

  4. Edit the same line differently: “- Master branching & merging”

  5. Commit on feature branch

  6. Switch to main → merge feature:

    Bash

→ Conflict!

  1. Open notes.txt — see markers:

    text
  2. Resolve: keep both or choose one → remove markers

  3. git add notes.txt

  4. git commit (auto message)

Goal: No longer panic when you see conflict markers — treat them as “Git needs your decision”

Exercise 5 – Reset & reflog recovery (the safety net)

  1. Make 3 small commits on main

  2. Do dangerous reset:

    Bash

→ Last commit disappeared!

  1. Panic? → git reflog

  2. Find the lost commit hash (second line usually)

  3. Recover:

    Bash

Goal: Trust that almost nothing is permanently lost if you act fast

Exercise 6 – Interactive rebase (clean history)

  1. Create branch with 5 messy commits (small changes + bad messages)

  2. git rebase -i HEAD~5

  3. In editor:

    • Change some pick to squash / fixup / reword / drop
    • Save & exit
  4. Edit combined message if asked

  5. git lg — clean, nice history

Goal: Feel comfortable rewriting your own private history

Exercise 7 – Rebase vs Merge (visual difference)

  1. Create branch A → 2 commits
  2. Update main → 1 commit
  3. On branch A: git rebase main → linear
  4. Create branch B → 2 commits
  5. On branch B: git merge main → merge bubble
  6. git lg –all — compare graphs

Goal: Understand why teams prefer rebase for personal branches + merge for shared

Exercise 8 – Stash emergency

  1. Make messy uncommitted changes on main
  2. Boss says: “quick fix on main!”
  3. git stash push -m “WIP dark mode”
  4. Fix something → commit → push
  5. git stash pop

Goal: Feel safe context switching

Exercise 9 – Cherry-pick one good commit

  1. Create branch with 3 commits — middle one is perfect
  2. Switch to main
  3. git cherry-pick <middle-hash>

Goal: Transplant only one change

Exercise 10 – .gitignore + .gitattributes practice

  1. Create .env, node_modules/, image.png, script.sh
  2. Create .gitignore → ignore .env, node_modules/
  3. Create .gitattributes → *.sh text eol=lf*.png binary
  4. git status — see what is ignored vs tracked

Goal: Automatic quality/safety

Final Advice (from your teacher)

Do these 10 exercises at least twice — once today, once tomorrow. Time yourself — aim for under 2 minutes per exercise.

After that:

  • Clone any open-source repo → make tiny fix → send PR
  • Break things on purpose → recover with reflog/reset
  • Set up Husky pre-commit hook
  • Use GitHub Desktop / GitKraken for visual help

You now have everything — from git init to advanced recovery, signing, LFS, hooks, CI/CD.

You’re ready to work in any team, contribute to open-source, pass any Git interview, and teach others.

Any final questions? Want me to give you a “Git final exam” with 10 random scenarios to solve?

Or shall we celebrate — you did it! 🎉

You’ve earned it. Very proud of you! 🚀

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *