Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk5 min

Stop Being Scared of Git: Learn the Model, Then Quiz the Commands

Git commands make more sense when you know the states they inspect or change. Learn the working tree, index, commits and branches, then test yourself with a practical command quiz.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Stop being scared of Git by learning what each command reads or changes. Start with three places your work can be: the working tree (files you are editing), the index or staging area (the content proposed for the next commit), and the last commit (the saved snapshot). Once those are clear, Git commands become less like magic and more like moves between known states.

The Git project says understanding its data model is not required to use Git, but is helpful for understanding terms such as “object,” “reference” and “index.” Git’s data-model documentation is the foundation for the model below.

As an Amazon Associate I earn from qualifying purchases.

What are Git’s three everyday states?

Use this as a comparison map, not a picture of Git’s physical storage:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

last commit (HEAD) ← index / staging area ← working tree

  • Working tree: the files in your checkout, including edits you have not staged.
  • Index: the proposed content of the next commit. It records what you staged, not necessarily the latest version currently in your working tree.
  • Last commit: the committed snapshot at the current point in history. HEAD identifies the current position, usually through the branch you have checked out.

Git’s model includes objects, references, the index and reflogs. Objects are immutable once created; everyday changes create new objects or update references rather than editing an existing commit in place. A commit identifies a snapshot and its parent commit or commits. Most commits have one parent; a merge commit can have more.

A branch name is a reference to a commit. When you commit while on a branch, Git advances that branch reference to the new commit. Switching branches changes the checked-out branch and updates the working tree to match it. History is therefore a graph of snapshots and parent links, not simply a stack of file diffs.

How can you tell what changed?

What does git status inspect?

git status reports the current branch and summarizes differences between the working tree, index and last commit. It inspects; it does not stage, commit or discard your edits.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What does git diff compare?

  • git diff compares the working tree with the index, showing changes that are not staged.
  • git diff --staged compares the index with the last commit (HEAD), showing what is staged for a future commit.

Those commands answer different questions. If a file has both staged and unstaged edits, use both comparisons to see each version of the change.

What does git add actually do?

git add file copies that file’s content as it exists when the command runs into the index. It does not create a commit. If you edit the file again afterward, the new edit remains in the working tree and is not silently added to the already-staged content. Run git add file again to update the index.

What does git commit save?

git commit creates a commit from the staged snapshot in the index and advances the current branch reference. It does not automatically include unstaged edits. Review git diff --staged before committing to inspect what the next snapshot contains.

How do branches and HEAD change?

What does git branch do?

With no arguments, git branch lists local branch names. Given a new name, it creates a branch reference; creation alone does not switch to it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What does git switch do?

  • git switch name checks out the existing branch named name, moving HEAD to it and updating the working tree as needed.
  • git switch -c name creates a branch and switches to it.

These explicit commands make branch changes easier to recognize than the older git checkout, which can switch branches or restore paths depending on how it is used.

How do you unstage or discard a file edit?

Keep the edit, but remove it from the next commit

git restore --staged file restores the index version of that path from HEAD. The working-tree edit remains, but it is no longer staged.

Discard an unstaged working-tree edit

git restore file replaces the working-tree content with the version in the index. This discards unstaged edits to that path. If the index already contains staged changes, those staged changes remain as the restored working-tree version.

Prefer git restore when the intent is to restore file content and git switch when the intent is to change branches. Older git checkout supports both jobs, which is why it can feel overloaded; use its explicit forms rather than treating it as a general-purpose undo command.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What does git reset change?

git reset moves the current branch or HEAD to a selected commit; its mode determines whether it also changes the index or working tree. It is not the same as restoring one file.

Command HEAD / current branch Index Working tree
git reset --soft commit Moves to the selected commit Left unchanged Left unchanged
git reset commit (default, mixed) Moves to the selected commit Reset to that commit Left unchanged
git reset --hard commit Moves to the selected commit Reset to that commit Reset to that commit; affected uncommitted changes can be discarded

Before using reset, identify which layer you intend to change and inspect the status and diffs. In particular, git reset --hard can discard uncommitted changes in affected paths; it is not a safe general undo button.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Quiz: what state changes?

For each situation, predict what Git reads or changes before checking the answer.

  1. You run git status. Which state changes?

    Answer: None. Git reports the branch and differences among tracked working-tree content, index and last commit.

    Free tools Windows power users keep installed

    One-click scans. No signup required.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  2. You edit notes.txt, then run git diff. What is compared?

    Answer: Working tree against index. The unstaged edit appears; the command does not change either state.

  3. You run git add notes.txt, then edit the file again. What will git diff and git diff --staged show?

    Answer: The first version, captured when git add ran, is in the index. git diff --staged shows that staged version against HEAD; git diff shows the later working-tree edit against the index. Stage the file again if the later edit should be included in the next commit.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  4. You run git commit without staging that later edit again. What is saved?

    Answer: The index snapshot, including the earlier staged version. The later unstaged edit remains in the working tree, and the new commit advances the current branch.

  5. You run git branch topic, then git switch topic. What happens at each step?

    Answer: The first command creates a branch reference but leaves you on the current branch. The second moves HEAD to topic and updates the working tree for that branch. You could create and switch in one command with git switch -c topic.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  6. You stage notes.txt and run git restore --staged notes.txt. What remains?

    Answer: The file is removed from the index’s proposed next snapshot, while its working-tree content remains. If that content differs from HEAD, it is now an unstaged edit.

  7. You run git restore notes.txt while the file has unstaged edits. What is lost?

    Answer: The working-tree version is replaced by the index version, so the unstaged edits to that path are discarded. The index itself is not changed.

    What’s actually slowing this PC down?

    Pick the symptom - the matching free tool is one click away.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Where can you keep learning?

The Git project’s Learn Git page links to beginner videos, a cheat sheet and further learning resources. The free online Pro Git, Second Edition is available on the official site. A print edition of that second edition is also listed there; it is a 2014 edition, while the project site says the third edition is in progress: Pro Git — the book about Git, free and open source. The printed second edition may suit readers who prefer paper, but it should not be mistaken for a newer edition than the online book.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.