Branching from Historical Commits
What
By default, creating a new branch copies the state of the current active commit (usually the tip of main). However, Git allows you to branch off of any historical commit in your repository’s timeline.
How
You can specify a target commit hash directly when creating a new branch with git switch -c or git branch:
# Create and switch to a new branch originating from a specific historical commit
git switch -c my_custom_feature <commit_hash>
To verify that the branch was successfully base-pinned to the past state, you can check that the specified commit hash is now the latest commit at the tip of your new active branch:
# View the latest commit on the current active branch
git log --oneline -n 1
Why
Branching from historical commits is incredibly useful for reproducing bugs reported on older software releases, hotfixing past versions of your project without pulling in newer, half-finished features, or testing experimental refactors from a clean baseline.
Summary
Pass a specific commit hash to git switch -c <branch_name> <commit_hash> to create a new branch originating from a past point in your repository’s timeline.