1 Quizzes•7 Questions

Learn Git

Commits, branches, merges and undoing mistakes: the workflows you use daily, with the reasoning behind them.

What you will practise

  • The three areas: working tree, index, repository
  • Branching and merging
  • Undoing changes safely

Git lesson

A short introduction to the ideas behind the quizzes, before you start practising.

Git tracks changes to your project as a history of snapshots. Almost every Git confusion comes from not knowing which of the three areas — working directory, staging area, commit history — a change currently sits in.

Key concepts

Working directory, staging area, repository

Edited files live in your working directory. `git add` moves a snapshot of them into the staging area. `git commit` records what is staged as a new point in the project’s history.

git add index.html
git commit -m "Add homepage"

Branching and merging

A branch is a movable pointer to a commit, letting you work on a feature without touching the main line of history. Merging brings another branch’s changes into your current branch, creating a merge commit if the histories diverged.

git switch -c feature/login
# ...make commits...
git switch main
git merge feature/login

Undoing changes safely

For changes not yet pushed, `git reset` can move a branch back; for changes already shared with others, `git revert` is safer because it adds a new commit that undoes an earlier one instead of rewriting history others may have already pulled.

git revert <commit-hash>   # safe on shared branches
git reset --soft HEAD~1    # only for local, unpushed commits

Remotes: fetch, pull, push

`git fetch` downloads the latest commits from a remote without changing your working branch. `git pull` is a fetch followed by a merge (or rebase). `git push` uploads your local commits to the remote.

git fetch origin
git pull origin main
git push origin feature/login

Common mistakes

  • Running `git reset --hard` without checking `git status` first, which can permanently discard uncommitted work.
  • Force-pushing (`git push --force`) to a shared branch, overwriting commits that teammates already based work on.
  • Committing generated files or secrets because `.gitignore` was added too late, so they were already tracked.
  • Confusing `git fetch` (safe, downloads only) with `git pull` (downloads and merges into your current branch).

Quick recap

  • Changes move from working directory, to the staging area, to the commit history.
  • Branches are lightweight pointers; merging combines their histories.
  • Prefer revert over reset once a commit has been pushed and shared.
  • Fetch is safe and non-destructive; pull also merges, so know which one you mean.

Ready to test this? Take the Git Basics quiz →

Roadmap

Work through the levels in order, or jump to where you are.

1

Beginner

Everyday Git

  • add/commit
  • Branches
  • Merge
  • Undo

Git Basics

Git quizzes

Interactive Git challenges

Hands-on activities: find bugs, complete code, order steps and match concepts.

All Git challenges →

Git articles

FAQ

Is this about GitHub?

These quizzes cover Git itself. Hosting features such as pull requests are not included.

Will this teach me how to resolve merge conflicts?

We test your conceptual understanding of why conflicts happen and how Git tracks changes. Interactive conflict resolution is best learned in an actual terminal.

Why do you ask about the "three areas"?

Because understanding the working tree, the index (staging area), and the commit history is the key to never losing your work in Git.