Committing to Branches

What

When you are on an active branch and make a new commit, Git automatically updates the branch pointer to reference the new commit hash, moving the tip of that branch forward while leaving other branch pointers unchanged.

How

By branching off of main and making a commit, you diverge your timelines:

          D    add_classics (active branch)
         /
A - B - C      main

When you are on add_classics and commit your changes:

  • A new commit D is created.
  • The parent of D is set to C (where you originally branched off).
  • The add_classics pointer moves to point directly to D.
  • The main branch pointer remains stationary at C.
# Verify the active branch tip in the logs
git log --oneline

Why

This automatic pointer progression is the magic that makes Git work. It allows you to freely create new history on your feature branch without any risk of polluting the main branch. Other developers (or you) can switch back to main at any time and get a stable, clean environment that is completely unaware of the experimental work happening on your feature branch.

Summary

Making a commit on an active branch automatically advances that branch’s pointer to the new commit, safely diverging its history from all other branches.