Git Branches as Pointers

Real Examples from feature/fix_code_quality

A practical demonstration using actual commit history from the road-profile-viewer repository.

Software Engineering | WiSe 2025 | Git Branches as Pointers

Example 1: Before Creating the Branch

State on 2025-10-21 at 16:26:11 (on main)

"Initial commit"
8177296
"change user name..."
92c2df3
lecture-01
"füge ruff hinzu"
91d5918
"remove C$ from ruff"
beaea6c
main
HEAD
  • beaea6c is the actual commit (snapshot: "remove C$ from ruff settings")
  • main is a branch pointer pointing to commit beaea6c
  • HEAD points to main (you're currently on the main branch)
  • lecture-01 tag points to commit 92c2df3
Software Engineering | WiSe 2025 | Git Branches as Pointers

Example 1: Creating the Branch

Command:

$ git checkout -b feauture/fix_code_quality
# (note: had the typo originally!)

After creating the branch:

"Initial commit"
8177296
"change user name..."
92c2df3
lecture-01
"füge ruff hinzu"
91d5918
"remove C$ from ruff"
beaea6c
main
feature/fix_code_quality
HEAD
Software Engineering | WiSe 2025 | Git Branches as Pointers

Example 1: What Just Happened?

  1. Git created a NEW pointer called feauture/fix_code_quality
  2. This pointer points to the SAME commit as main (beaea6c)
  3. Git moved HEAD to point to the new branch
  4. No commits were created or copied - just a new pointer!

Key insight: Creating a branch is cheap - it's just creating a pointer (a few bytes)!

Software Engineering | WiSe 2025 | Git Branches as Pointers

Example 2: First Commit on Branch

Making the first commit:

$ vim main.py  # Fix code formatting
$ git add main.py
$ git commit -m "fix code formatting using ruff format"

Before the commit:

...
...
"remove C$ from ruff"
beaea6c
main
feature/fix_code_quality
HEAD
Software Engineering | WiSe 2025 | Git Branches as Pointers

Example 2: After First Commit

After the commit (032f36c):

...
...
"remove C$ from ruff"
beaea6c
main
"fix code formatting"
032f36c
feature/fix_code_quality
HEAD

What happened:

  1. Git created NEW commit 032f36c
  2. Git moved the feauture/fix_code_quality pointer forward to 032f36c
  3. The main pointer stayed at beaea6c (unchanged!)
  4. HEAD still points to feauture/fix_code_quality
Software Engineering | WiSe 2025 | Git Branches as Pointers

Example 2: Key Insight

Only the current branch pointer moves when you commit.

Other branches stay where they are!

This is how feature branches provide isolation - your work on the feature branch doesn't affect main.

Software Engineering | WiSe 2025 | Git Branches as Pointers

Example 3: After Multiple Commits

Making more commits:

$ git commit -m "lasse ruff check laufen..."  # e341990
$ git commit -m "style: fix code quality..."  # 1ff0a77

Final state after 3 commits on branch:

...
8177296
"remove C$"
beaea6c
main
"fix formatting"
032f36c
"lasse ruff..."
e341990
"style: fix..."
1ff0a77
feature/fix_code_quality
HEAD
Software Engineering | WiSe 2025 | Git Branches as Pointers

Example 3: Visualizing the Divergence

"remove C$"
beaea6c
main
↑ main is here
"fix formatting"
032f36c
"lasse ruff..."
e341990
"style: fix..."
1ff0a77
↑ feature moved 3 commits

What we see:

  • main is still at beaea6c (where we branched from)
  • feauture/fix_code_quality has moved forward through 3 commits
  • The feature branch work is isolated from main
  • HEAD points to the feature branch (we're working on it)
Software Engineering | WiSe 2025 | Git Branches as Pointers

Example 4: Switching Branches

Switching back to main:

$ git checkout main

Before the checkout:

"style: fix code quality"
1ff0a77
feature/fix_code_quality
HEAD

After the checkout:

"remove C$ from ruff"
beaea6c
main
HEAD
Software Engineering | WiSe 2025 | Git Branches as Pointers

Example 4: What Changed?

Only HEAD moved!

  • HEAD moved from feature branch pointer to main pointer
  • Your working directory changed to show commit beaea6c
  • The branch pointers themselves didn't move
  • feauture/fix_code_quality still points to 1ff0a77

This is all that git checkout does - it moves the HEAD pointer!

Software Engineering | WiSe 2025 | Git Branches as Pointers

Example 5: Merging Feature Branch

When you merge the feature branch:

$ git checkout main
$ git merge feauture/fix_code_quality
# (Or merge via GitHub PR)

Result: Fast-forward merge

"remove C$"
beaea6c
main
"fix formatting"
032f36c
"lasse ruff..."
e341990
"style: fix..."
1ff0a77
feature/fix_code_quality
Software Engineering | WiSe 2025 | Git Branches as Pointers

Example 5: After the Merge

After the merge (fast-forward):

"remove C$"
beaea6c
"fix formatting"
032f36c
"lasse ruff..."
e341990
"style: fix..."
1ff0a77
main
feature/fix_code_quality
HEAD

What happened:

  • Git moved the main pointer forward to 1ff0a77
  • This is a "fast-forward" merge (main just catches up)
  • Both main and feauture/fix_code_quality now point to the same commit
  • No merge commit was needed (linear history)
Software Engineering | WiSe 2025 | Git Branches as Pointers

Example 6: Adding a Tag

Creating the lecture-04 tag:

$ git tag -a lecture-04 -m "End of Chapter 02 (Refactoring): Code quality fixes"

Current state with tag:

"Initial commit"
8177296
"change user..."
92c2df3
lecture-01
...
...
"style: fix..."
1ff0a77
main
feature/fix_code_quality
lecture-04
HEAD

All four pointers point to the SAME commit 1ff0a77!

Software Engineering | WiSe 2025 | Git Branches as Pointers

Example 6: Tags are Also Pointers

Tags are just like branches - they're pointers to commits!

The difference:

  • Branch pointers move forward when you commit
  • Tag pointers never move (permanent markers)

Both are just references to commits - not copies of commits.

Software Engineering | WiSe 2025 | Git Branches as Pointers

Example 7: Renaming the Branch

Fixing the typo:

$ git branch -m feauture/fix_code_quality feature/fix_code_quality

What happened:

Before rename:

"style: fix code quality"
1ff0a77
feauture/fix_code_quality
(typo in name)

After rename:

"style: fix code quality"
1ff0a77
feature/fix_code_quality
(fixed spelling)
Software Engineering | WiSe 2025 | Git Branches as Pointers

Example 7: The Commit Never Changed

The commit 1ff0a77 never changed!

We just:

  1. Created a new pointer with the correct spelling
  2. Deleted the old pointer with the typo

This is why:

  • The tag lecture-04 still works (points to commit, not branch name)
  • Anyone who checked out the tag never saw the typo
  • Branches are just labels, not the actual code
Software Engineering | WiSe 2025 | Git Branches as Pointers

Summary: Branches as Pointers

Key takeaways:

  1. Commits are the actual snapshots (never change once created)
  2. Branches are lightweight, movable pointers to commits
  3. Tags are lightweight, permanent pointers to commits
  4. HEAD is a special pointer showing "you are here"

When you:

  • Create a branch → Create a new pointer
  • Make a commit → Move current branch pointer forward
  • Switch branches → Move HEAD to different branch pointer
  • Merge branches → Move target branch pointer forward
  • Rename a branch → Create new pointer, delete old one
Software Engineering | WiSe 2025 | Git Branches as Pointers

Why This Matters

Understanding branches as pointers helps you:

  1. Understand Git commands - Know what's really happening
  2. Work confidently - No fear of "breaking" things
  3. Debug issues - Understand where you are and why
  4. Use advanced features - Rebase, cherry-pick, etc.

Git becomes less magical and more logical!

Software Engineering | WiSe 2025 | Git Branches as Pointers

Practical Application

In your daily workflow:

# Creating a branch? Just creating a pointer!
$ git checkout -b feature/new-feature

# Making commits? Moving the branch pointer forward!
$ git commit -m "Add feature"

# Switching branches? Moving HEAD!
$ git checkout main

# Merging? Moving the target branch pointer!
$ git merge feature/new-feature

Every Git command is just manipulating these pointers!

Software Engineering | WiSe 2025 | Git Branches as Pointers

Questions?

Remember:

  • Branches ≠ Commits
  • Branches = Pointers to commits
  • This is why branches are fast, cheap, and powerful!

Try it yourself:

$ git log --oneline --graph --all --decorate

See all the pointers (branches, tags, HEAD) and which commits they point to!

Software Engineering | WiSe 2025 | Git Branches as Pointers

Additional Resources

From the lecture file:

  • Section 4.2: The Technical Reality: Branches Are Pointers
  • Section 4.3: Why Use Branches?

Interactive learning:

Official documentation: