---
title: "Version Control as a Graph of Commits"
description: "In Git, history is a directed graph of snapshot commits. A root commit has no parents, an ordinary commit has one, and a merge can have several. Branches are movable labels. HEAD points to the current"
canonical: https://lightmysky.com/learn/computing/version-control-as-a-graph-of-commits-mt_oKsDRKirMy
source: https://lightmysky.com/learn/computing/version-control-as-a-graph-of-commits-mt_oKsDRKirMy.md
retrieved: 2026-11-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Version Control as a Graph of Commits

In Git, history is a directed graph of snapshot commits. A root commit has no parents, an ordinary commit has one, and a merge can have several. Branches are movable labels. HEAD points to the current branch name or directly to a commit.

Subject: Computing · Area: Software Engineering · Ages 18 to 19
Page: https://lightmysky.com/learn/computing/version-control-as-a-graph-of-commits-mt_oKsDRKirMy

## Ready when they can

- Draw the commit graph of a short history and mark where each branch label sits
- Say what changes in the graph when a commit is made and when a branch is created
- Explain detached HEAD as a direct pointer to a commit rather than a pointer to a branch name

## Lesson: History as a graph of snapshots

Git can save a program's stages as commits. Each commit records a snapshot and links to its parent commits. A root commit has no parents. An ordinary commit has one; a merge can have two or more. To draw the history, draw one node per commit and an arrow from each commit to each parent. Parent links point to commits that already existed, so following them cannot lead back to the starting node.

*(drawing: These records name the parents. To draw their graph, add arrows from K to J and from L to K.)*

A branch is a movable label pointing to a commit. HEAD usually points to the current branch name. When you make an ordinary commit on that branch, the new commit's parent is the branch's previous tip. The branch moves to the new commit, while HEAD still points to the branch name. Other branches stay put.

**Example.** Start with root commit J, then make ordinary commits K and L on main. HEAD points to main. Creating draft at L adds a label but no commit and does not switch HEAD. Switch to draft, then make M. M has parent L, draft moves to M, main stays at L, and HEAD still points to draft. To reconstruct the graph, draw arrows from M to L, L to K and K to J, with none from J. Place main at L and draft at M.

Checking out a commit by its ID makes HEAD point directly to that commit, rather than to a branch name. This is detached HEAD, even if a branch points to the same commit. An ordinary commit made here uses HEAD's previous commit as its parent. HEAD moves to the new commit, but no branch moves.

After making detached commits, switching to main makes HEAD point to main. It does not merge or immediately delete the detached commits. If no branch leads to them, they can be harder to find. A local reflog can record recent moves of HEAD and branch references and may help you find them for a time. Its entries can expire.

Before switching away from detached work, create a branch at its latest commit. A commit is reachable from a branch if it is the branch's tip or you can follow parent links from the tip to it. If detached commits T then U were added after L, a branch at U keeps U, T and L reachable. A branch at L does not reach T or U because parent links lead toward older commits.

**Recap.** Commits link to parents. Branches point to commits. HEAD points to a branch name or directly to a commit. A branch at detached work's latest commit keeps that history reachable.

*Git commit-history lesson revisions, questions and flashcard revisions written for this dataset.*

## Practice

8 questions on this page, each with its working shown.

## Needs first

- [The Project Arc: Building a Program in Stages](https://lightmysky.com/learn/computing/the-project-arc-building-a-program-in-stages-mt_hACOaB3nA_)

## Optional connections

- [Graphs and How to Store Them](https://lightmysky.com/learn/computing/graphs-and-how-to-store-them-mt_tSO-F1sTuu)

## Opens up

- [Branching, merging and resolving a conflict](https://lightmysky.com/learn/computing/branching-merging-and-resolving-a-conflict-mt_l3vFbU7L3E)
- [Reproducibility in Practice: Data, Code and What Another Lab Can Rerun](https://lightmysky.com/learn/science/reproducibility-in-practice-data-code-and-what-another-lab-can-rerun-mt_QuHuEyasFt)
