Learning Git basics like git add, commit, and push is great — but what happens when things go wrong? What if you commit buggy code, or push something to the remote repo that shouldn’t be there?
In my latest Git tutorial video, I walk through how to fix common mistakes with three powerful commands: git reset, git revert, and git rebase. Knowing these will give you confidence that you can undo mistakes cleanly and keep your code history tidy.
Why Basics Aren’t Enough
When I first learned Git, I was only taught the basics — add, commit, push. But inevitably, bugs happen, or you commit something you regret. You need more than just the basics.
In this video, I start with a simple repository that contains a basic hello world C program and walk you through intentionally adding mistakes, then fixing them.
Using git reset to Undo Local Commits
If you’ve committed a bug but haven’t pushed it yet, git reset is your friend.
git reset moves your branch pointer back to an earlier commit, effectively “undoing” commits. The code changes remain in your working directory, so you can fix bugs before recommitting.
For example, if you want to reset the last commit, you can run:
git reset HEAD~1
This points your branch back one commit, but keeps your code changes unstaged so you can update and recommit.
If you want to discard changes entirely and reset to a clean state, use:
git reset --hard HEAD~1
Be cautious with the --hard option because it will wipe out all your uncommitted changes!
When to Use git revert for Remote Commits
If you already pushed your buggy commit to a shared remote branch, don’t use git reset — rewriting history can mess up everyone else’s work.
Instead, use git revert to create a new commit that undoes the effects of a previous commit without changing history.
For example:
git revert HEAD
This generates a new commit that reverses the buggy commit but keeps the history intact.
In the video, I show how after pushing a buggy commit, you can revert it safely and push the fix so everyone stays in sync.
Understanding git rebase for Keeping Your Branch Updated
git rebase isn’t about fixing mistakes per se — it’s about applying your commits on top of another branch’s commits.
Say you’re working on a feature branch and the main branch has new commits you want to include. Instead of merging, you can rebase your branch onto main, creating a cleaner history.
This involves:
- Checking out your branch
- Running
git rebase main - Resolving any merge conflicts manually
- Continuing the rebase until complete
Rebasing keeps commit history linear and easier to follow, which is especially helpful in team projects.
Summary: When to Use Each Command
git reset— Undo commits before pushing; lets you rewrite local history.git revert— Undo commits after pushing; preserves commit history with a new “undo” commit.git rebase— Update your branch on top of another branch’s commits; helps keep history clean and linear.
Watch the Full Tutorial
This walkthrough and demo is all in my video here:
Fix Git Mistakes with git reset, git revert & git rebase — Full Tutorial
Bonus: Get My Free Git Starter Guide
If Git still feels overwhelming, I made a free Git Starter Guide PDF + videos to help you build solid Git workflow skills step-by-step. Grab it below and start mastering Git confidently.
Let me know in the comments if you want a deeper dive into git reset with forced pushes or more on rebasing strategies. Happy coding!

