A practical demonstration using actual commit history from the road-profile-viewer repository.
State on 2025-10-21 at 16:26:11 (on main)
beaea6c
main
HEAD
lecture-01
92c2df3
Command:
$ git checkout -b feauture/fix_code_quality # (note: had the typo originally!)
After creating the branch:
feauture/fix_code_quality
Key insight: Creating a branch is cheap - it's just creating a pointer (a few bytes)!
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:
After the commit (032f36c):
What happened:
032f36c
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.
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:
What we see:
Switching back to main:
$ git checkout main
Before the checkout:
After the checkout:
Only HEAD moved!
1ff0a77
This is all that git checkout does - it moves the HEAD pointer!
git checkout
When you merge the feature branch:
$ git checkout main $ git merge feauture/fix_code_quality # (Or merge via GitHub PR)
Result: Fast-forward merge
After the merge (fast-forward):
Creating the lecture-04 tag:
$ git tag -a lecture-04 -m "End of Chapter 02 (Refactoring): Code quality fixes"
Current state with tag:
All four pointers point to the SAME commit 1ff0a77!
Tags are just like branches - they're pointers to commits!
The difference:
Both are just references to commits - not copies of commits.
Fixing the typo:
$ git branch -m feauture/fix_code_quality feature/fix_code_quality
Before rename:
After rename:
The commit 1ff0a77 never changed!
We just:
This is why:
lecture-04
Key takeaways:
When you:
Understanding branches as pointers helps you:
Git becomes less magical and more logical!
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!
Remember:
Try it yourself:
$ git log --oneline --graph --all --decorate
See all the pointers (branches, tags, HEAD) and which commits they point to!
From the lecture file:
Interactive learning:
Official documentation: