LearnThatStack Ace your next interview
Computer Science Fundamentals

Git & Version Control.

Start free Change topic Change

Practise Git & Version Control one question at a time. Answer out loud or in writing, get graded, and see exactly what you missed.

Try one question

What is Git and how does it differ from centralized version control systems?

The answer

Git is a distributed version control system, so every clone holds the whole history. Centralized systems like Subversion or CVS keep the history on one server, and each client holds a working copy of the current files.

Git's history is local. You can commit, read the log, and compare versions with no network.

Aspect Git (distributed) Centralized (SVN, CVS)
Full history in every clone on the server only
Commit and read history local, no network need the server
Branching cheap and local server-side, needs network
Server outage any clone still has the full history no commits until it returns

The trade-off is that your commits stay private until you push, and teammates see them only after they fetch.

Example · what grading looks like
How do you undo your most recent commit without losing the work?

“I'd run git reset --soft HEAD~1, which moves the branch back one commit but leaves all my changes staged, so I can fix things up and commit again. If I'd rather have the changes unstaged, a plain git reset HEAD~1 does the same thing, and I'd stay away from --hard because that throws the edits away.”

Knew it

They've got the soft reset keeping changes staged and the mixed-reset unstaged, and know to avoid --hard. A real interview would also want to hear how this differs from revert once a commit is pushed.

Missed: Doesn't mention that reset only rewrites local history, so a pushed commit should be undone with revert instead.


Get your own answers graded

Sign up free. Your account comes with 50 credits for grading, and it remembers what you missed.

What it covers

All 54 questions

Each on its own page

Git basics and the staging area

What Git is, how it differs from GitHub and centralized systems, and how the index, staging and .gitignore decide what goes into a commit.

5 questions

  1. What is Git and how does it differ from centralized version control systems?
  2. What is the difference between Git and GitHub, and why does it matter?
  3. What is the staging area, and why does Git separate it from commits?
  4. What is a .gitignore file, and how does Git decide what to ignore? Pro
  5. What is the index file, and how does it make git status fast? Pro

Branches, HEAD and tags

Branches as movable pointers, detached HEAD, lightweight versus annotated tags, and checking out several branches at once with worktrees.

5 questions

  1. What is a branch in Git, and how do you create and switch one? Pro
  2. Is a Git branch really just a movable pointer to a commit? Pro
  3. What does detached HEAD mean, and how do you end up there? Pro
  4. What is the difference between lightweight and annotated tags, and when do you use each? Pro
  5. What is git worktree, and when would you use it? Pro

Merging and conflict resolution

Merge versus rebase, fast-forward and merge commits, how a three-way merge uses the merge base, and resolving conflicts, including with rerere.

5 questions

  1. When should you use git merge versus git rebase to combine branches?
  2. How do you resolve a merge conflict, step by step, without panicking?
  3. What is the difference between a fast-forward merge and a merge commit? Pro
  4. What is git rerere, and how does it help with repeated conflict resolution? Pro
  5. How does a three-way merge work, and what is the merge base? Pro

Remotes, fetching and pushing

Clones, forks and bare repos, fetch versus pull, upstream tracking branches, refspecs, and force-pushing safely with --force-with-lease.

7 questions

  1. What is the difference between git fetch and git pull?
  2. How do you clone a repository and connect it to a remote? Pro
  3. How does a fork differ from a clone, and how do you keep it in sync? Pro
  4. What is an upstream tracking branch, and how does it shape push and pull? Pro
  5. Why prefer git push --force-with-lease over a plain force push? Pro
  6. What is a bare repository, and why do servers host repos that way? Pro
  7. How do refspecs control what fetch and push actually map between repos? Pro

Undoing changes and recovery

Undoing commits and local edits with reset, revert, restore and stash, and getting lost work back with the reflog after a bad reset or rebase.

7 questions

  1. How do you undo your most recent commit without losing the work?
  2. How do you throw away uncommitted local changes you no longer want? Pro
  3. What is the difference between reset --soft, --mixed, and --hard? Pro
  4. When do you reach for reset versus revert versus checkout? Pro
  5. What does git stash do, and when does it come back to bite you? Pro
  6. How does git reflog let you recover commits you thought were lost? Pro
  7. How do you recover cleanly after a rebase goes badly wrong? Pro

Rewriting history

Amend, cherry-pick and interactive rebase, why shared history should not be rewritten, and repo-wide rewrites such as scrubbing a leaked secret.

6 questions

  1. When is git cherry-pick the right tool, and what are its dangers? Pro
  2. What can interactive rebase do, and how do you squash commits safely? Pro
  3. Why should you never rebase commits you have already pushed and shared? Pro
  4. What does git commit --amend do, and when is it unsafe? Pro
  5. How do you rewrite history across an entire repo, and what breaks downstream? Pro
  6. A secret got committed and pushed, how do you fully remediate it? Pro

Investigating history

Finding when and why code changed: git blame for a line's origin, git bisect to find a bad commit, and how Git detects renames.

3 questions

  1. What does git blame do, and when would you use it? Pro
  2. How does git bisect find a bad commit across thousands of revisions? Pro
  3. How does Git detect file renames when it stores no rename history? Pro

Team workflows and safeguards

Branching strategies, pull request merge styles, long-lived branches, commit messages, hooks, and signed commits that keep a team's history trustworthy.

6 questions

  1. What makes a good commit message, and why does it matter later? Pro
  2. Should you squash, merge, or rebase a pull request, and why? Pro
  3. How do Git Flow, GitHub flow, and trunk-based development differ? Pro
  4. What are Git hooks, and where do client-side and server-side ones differ? Pro
  5. How do you sign commits and verify who actually authored them? Pro
  6. How do you keep a long-lived feature branch healthy against a moving main? Pro

Object model and storage

Commits, trees and blobs as content-addressed snapshots, SHA hashing, loose objects and packfiles, and what git gc removes.

6 questions

  1. What actually happens under the hood when you run git commit? Pro
  2. Is a Git commit a full snapshot or a diff, and why? Pro
  3. How do commits, trees, and blobs fit together in Git's object model? Pro
  4. How does Git store objects as loose files and later pack them? Pro
  5. How does Git hash content, and should you worry about SHA collisions? Pro
  6. What happens during git gc, and when can it delete unreachable commits? Pro

Scaling large repositories

Keeping big repos workable: monorepo performance, shallow and partial clones, Git LFS for binaries, and submodules versus subtrees.

4 questions

  1. Why do large binary files hurt a Git repo, and how does LFS help? Pro
  2. Submodules versus subtrees for vendoring code, what tradeoffs do you weigh? Pro
  3. How do you keep Git fast in a huge monorepo with millions of files? Pro
  4. When is a shallow or partial clone worth its later limitations? Pro
Practice · Questions

All questions

Showing of 54
Beginner 14
01

What is Git and how does it differ from centralized version control systems?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Git is a distributed version control system, so every clone holds the whole history. Centralized systems like Subversion or CVS keep the history on one server, and each client holds a working copy of the current files.

Git's history is local. You can commit, read the log, and compare versions with no network.

Aspect Git (distributed) Centralized (SVN, CVS)
Full history in every clone on the server only
Commit and read history local, no network need the server
Branching cheap and local server-side, needs network
Server outage any clone still has the full history no commits until it returns

The trade-off is that your commits stay private until you push, and teammates see them only after they fetch.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

02

What is the difference between Git and GitHub, and why does it matter?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Git is the version control program on your machine, and GitHub is a service that hosts Git repositories online and adds tools around them.

Git GitHub
What it is a command-line tool a hosting service built on Git
Main features git commit, git branch, git merge Pull requests, issues, code review
Where history lives .git on your disk a hosted copy of the repository
Team extras none built in access control, Actions for CI

It matters because Git works without GitHub. Your full history lives in .git on your disk, so you can work offline even when GitHub is down.

Switching hosts means pointing your remote, the address Git pushes to and fetches from, at a new URL. Git itself does not change, and hosts like GitLab or Bitbucket serve the same repositories.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

03

What is the staging area, and why does Git separate it from commits?

Visual

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain
Visual

The staging area, or index, is where you build your next commit. git add copies a file's current content into the index. git commit turns whatever is staged into the new commit.

The separation lets you choose what goes in: the fix, not the debug print. git add -p goes further and lets you pick single hunks of one file.

git add stages the content, not the file, so edits made after it stay out of the commit until you add them again.

git diff            # working files vs staging area
git diff --staged   # staging area vs last commit
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

04

How do you undo your most recent commit without losing the work?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

git reset --soft HEAD~1 undoes the last commit and keeps the changes staged, ready to commit again. Reset moves the branch pointer back one commit. Your files on disk never change.

git reset --soft HEAD~1   # commit undone, changes stay staged
git reset HEAD~1          # same, but changes end up unstaged

The default mode, --mixed, keeps the work unstaged instead. The --hard mode throws away your edits, so avoid it here.

Reset only moves your local branch, so use git revert HEAD for a commit you already pushed. Revert adds a new commit that undoes the old one, and nobody's history is rewritten.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

05

When should you use git merge versus git rebase to combine branches?

Visual

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain
Visual

Use merge on shared branches. Use rebase to tidy your own branch before others pull it.

git merge records the join in a new commit and rewrites nothing, so merge is safe everywhere. The cost is a busier history, because every merge of diverged branches adds a merge commit.

git rebase replays your commits onto the other branch. The copies get new hashes, so they are new commits. Anyone who already had the old ones now holds a diverged branch, which is why you never rebase shared history.

Concern git merge git rebase
History branch and join one straight line
Existing commits kept as they are replaced by copies with new hashes
Conflicts fixed once can repeat per replayed commit

A common workflow uses both. Rebase the feature branch onto the newest main, then merge it:

git switch feature
git rebase main     # replay my commits on the newest main
git switch main
git merge feature   # publish the finished work
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

06

How do you resolve a merge conflict, step by step, without panicking?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Find the conflicted files, edit each one into the version you want, then git add them and commit. A merge conflict only means both branches changed the same lines. Git stops, keeps both versions in the file, and waits for you to decide. Nothing is lost.

Run git status first. It lists the conflicted files under Unmerged paths. Open each one. Your side sits between <<<<<<< HEAD and =======. The incoming side follows, up to >>>>>>> branch-name.

Edit the file into the text you want, then delete all three marker lines. Often the right result keeps parts of both sides.

git status               # which files are unmerged
git add src/config.js    # staging a file marks it resolved
git commit               # finishes the merge
git merge --abort        # bail out, back to before the merge

There is no separate "resolve" command. git add is the signal. Run the build and tests before committing, because a file with no markers left can still be broken. If it goes wrong, git merge --abort before the commit puts everything back as it was.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

07

What is the difference between git fetch and git pull?

Visual

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain
Visual

git fetch only downloads new commits, while git pull downloads them and then integrates them into your current branch. Fetch updates your remote-tracking branches, local copies like origin/main. Fetch never changes your working files or your own branches, so it is always safe to run.

Pull integrates the upstream, the remote branch your branch tracks, and how it does that depends on your settings. By default current Git only fast-forwards, moving your branch ahead when you have no new commits of your own. A pull fails when your branch has diverged. git pull --rebase replays your commits on top instead, and git pull --no-rebase runs a merge. Set pull.rebase once to choose a default.

Command Updates origin/main Moves your branch Can conflict
git fetch yes no no
git pull yes yes yes

Fetching first lets you see what arrived before you decide how to combine it:

git fetch origin
git log --oneline main..origin/main   # what arrived
git merge origin/main                 # the step git pull --no-rebase does for you
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

08

What is a branch in Git, and how do you create and switch one?

Part of Pro
09

How do you throw away uncommitted local changes you no longer want?

Part of Pro
10

What is a .gitignore file, and how does Git decide what to ignore?

Part of Pro
11

How do you clone a repository and connect it to a remote?

Part of Pro
12

What does git blame do, and when would you use it?

Part of Pro
13

How does a fork differ from a clone, and how do you keep it in sync?

Part of Pro Visual
14

What makes a good commit message, and why does it matter later?

Part of Pro
Intermediate 25
15

What actually happens under the hood when you run git commit?

Part of Pro
16

Is a Git commit a full snapshot or a diff, and why?

Part of Pro Visual
17

How do commits, trees, and blobs fit together in Git's object model?

Part of Pro Visual
18

Is a Git branch really just a movable pointer to a commit?

Part of Pro Visual
19

What does detached HEAD mean, and how do you end up there?

Part of Pro Visual
20

What is the difference between reset --soft, --mixed, and --hard?

Part of Pro Visual
21

When do you reach for reset versus revert versus checkout?

Part of Pro Visual
22

What does git stash do, and when does it come back to bite you?

Part of Pro
23

When is git cherry-pick the right tool, and what are its dangers?

Part of Pro Visual
24

What is the difference between a fast-forward merge and a merge commit?

Part of Pro Visual
25

What can interactive rebase do, and how do you squash commits safely?

Part of Pro
26

Why should you never rebase commits you have already pushed and shared?

Part of Pro Visual
27

How does git reflog let you recover commits you thought were lost?

Part of Pro Visual
28

What is the difference between lightweight and annotated tags, and when do you use each?

Part of Pro
29

What is an upstream tracking branch, and how does it shape push and pull?

Part of Pro
30

Why prefer git push --force-with-lease over a plain force push?

Part of Pro Visual
31

What does git commit --amend do, and when is it unsafe?

Part of Pro Visual
32

Should you squash, merge, or rebase a pull request, and why?

Part of Pro Visual
33

How do Git Flow, GitHub flow, and trunk-based development differ?

Part of Pro
34

What is git worktree, and when would you use it?

Part of Pro
35

How does git bisect find a bad commit across thousands of revisions?

Part of Pro
36

How do you recover cleanly after a rebase goes badly wrong?

Part of Pro
37

Why do large binary files hurt a Git repo, and how does LFS help?

Part of Pro
38

What are Git hooks, and where do client-side and server-side ones differ?

Part of Pro
39

What is a bare repository, and why do servers host repos that way?

Part of Pro
Expert 15
40

How does Git store objects as loose files and later pack them?

Part of Pro Visual
41

How does Git hash content, and should you worry about SHA collisions?

Part of Pro
42

How does Git detect file renames when it stores no rename history?

Part of Pro
43

What is the index file, and how does it make git status fast?

Part of Pro
44

What is git rerere, and how does it help with repeated conflict resolution?

Part of Pro
45

Submodules versus subtrees for vendoring code, what tradeoffs do you weigh?

Part of Pro
46

How do you keep Git fast in a huge monorepo with millions of files?

Part of Pro
47

What happens during git gc, and when can it delete unreachable commits?

Part of Pro
48

When is a shallow or partial clone worth its later limitations?

Part of Pro Visual
49

How does a three-way merge work, and what is the merge base?

Part of Pro Visual
50

How do you rewrite history across an entire repo, and what breaks downstream?

Part of Pro
51

How do you sign commits and verify who actually authored them?

Part of Pro
52

A secret got committed and pushed, how do you fully remediate it?

Part of Pro
53

How do refspecs control what fetch and push actually map between repos?

Part of Pro Visual
54

How do you keep a long-lived feature branch healthy against a moving main?

Part of Pro

No matches

Try a different filter or search term.

Know someone prepping for Git & Version Control? Send them this set.
Quick recap

Git & Version Control in pictures.

A quick recap of Git & Version Control in 32 short animated pictures, one idea at a time. About 8 min to get the whole topic back in your head before you walk in. Pause any picture, slow it down, or step through it.

Pro The first chapter is free to play. The other 29 pictures come with Pro.

Get Pro · $10/mo
Pro · $10/mo

47 of 54 Git & Version Control answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime

Change topic

Pick a different technology or stack. Your current topic stays put until you choose a new one.

Technologies
No technologies match “”.
Cross-cutting topics
No topics match “”.
By role
Stacks & frameworks

MEAN

MongoDB, Express, Angular, Node.js

MERN

MongoDB, Express, React, Node.js

LAMP

Linux, Apache, MySQL, PHP

Django

Python Full-Stack Development

Ruby on Rails

Convention over Configuration

Serverless on AWS

Serverless Architecture on AWS

Flutter Mobile

Flutter Cross-Platform Mobile Development

Spring Boot

Enterprise Java Development

.NET

Microsoft Ecosystem

Vue

Vue.js, Vite, TypeScript, Tailwind, Node.js

Go Backend

Golang, gRPC, PostgreSQL, Redis, RabbitMQ

FastAPI

Python, FastAPI, SQLAlchemy, PostgreSQL

React Native

React, TypeScript, Redux, Firebase

iOS Native

Swift, SwiftUI, UIKit, Firebase

Android Native

Java, Jetpack Compose, Firebase

DevOps / Platform

Docker, Kubernetes, Terraform, CI/CD

AI Engineer

LLMs, RAG, Agents, Evals

AI-Powered Developer

Claude Code, Copilot, Agentic Workflows

Core SWE Interview Prep

Data structures, algorithms, OS, concurrency, networking, git