🔁 How I Rewound My Git Branch to Start Fresh (and Why You Might Too)
During development, it’s common to try different things, commit frequently, and end up with a branch history that feels messy or bloated. Recently, while working on a feature branch for my-ticket-2025
, I found myself wanting a clean slate—but without deleting everything. Here's how I surgically rewound my Git history and started fresh from a specific point.
🧠 The Scenario
I was working on a branch named feat/my-ticket-2025
. Here's a simplified view of the commit history:
a1b2c3d chore: update test - bff ← most recent
d4e5f6g chore: remove visa-related code
h7i8j9k chore: add docs ← I want to restart from here
z1x2c3v chore: update package-lock
After reflecting, I realized everything after chore: add docs
was experimental or unneeded. So, I decided to reset my branch to that specific commit, wiping the newer ones entirely.
🔨 The Goal
Reset the branch to the chore: add docs
commit as if the newer ones never happened.
⚙️ The Command That Did It
First, I located the commit hash for chore: add docs
:
git log --oneline
Then I executed:
git reset --hard h7i8j9k
Replace
h7i8j9k
with the actual commit hash from your log.
This erased everything after that commit — including local changes.
To update the remote branch and overwrite its history:
git push origin feat/my-ticket-2025 --force
⚠️ A Word of Caution
Using --hard
and --force
is powerful, but dangerous:
- Use
--hard
only if you're okay losing local changes. - Use
--force
only when you're sure others aren't working on the branch, or coordinate with your team first.
For safety, you can always create a backup branch before the reset:
git branch backup/my-ticket-2025
✅ Clean Slate, Happy Dev
After the reset, my branch had a clean history. I could now recommit only what truly mattered moving forward.
If you ever feel like your Git history has spiraled out of control — you can always pause, rewind, and restart. That’s the beauty of version control.
✍️ Have you used git reset --hard
before? Any horror stories or productivity wins? Drop them in the comments!