You need to make sure that no other users of this repository are fetching the incorrect changes or trying to build on top of the commits that you want removed because you are about to rewind history.

Then you need to 'force' push the old reference.

git push -f origin last_known_good_commit:branch_name

or in your case

git push -f origin cc4b63bebb6:alpha-0.3.0

You may have receive.denyNonFastForwards set on the remote repository. If this is the case, then you will get an error which includes the phrase [remote rejected].

In this scenario, you will have to delete and recreate the branch.

git push origin :alpha-0.3.0
git push origin cc4b63bebb6:refs/heads/alpha-0.3.0

If this doesn't work - perhaps because you have receive.denyDeletes set, then you have to have direct access to the repository. In the remote repository, you then have to do something like the following plumbing command.

git update-ref refs/heads/alpha-0.3.0 cc4b63bebb6 83c9191dea8
Answer from Lara Bailey on Stack Overflow
🌐
Graphite
graphite.com › guides › git-revert-commit-after-pushing
git revert commit after pushing
If you need to revert more than one commit, you can use the git revert to specify a range of commits: ... This command sequence reverts all changes in the specified range, combining them into a single commit. Communicate with your team: Before reverting commits that have been pushed, especially in shared repositories, inform your team about the changes.
🌐
Reddit
reddit.com › r/git › how to undo pushed commits
r/git on Reddit: How to undo pushed commits
January 29, 2024 -
  • One of our artists managed to push 1 month of progress without merging

  • As you can see I tried to undo the commits one by one in reverse order

  • I couldn't undo the merge commit of Arvincle because it's empty

  • When I try to revert the commit before that I get one file I need to merge first, but the rest of the changes are not undone

Is there a way to reset the HEAD of main to the last valid commit?

🌐
Warp
warp.dev › terminus by warp › git › undo a git push
How to undo a git push | Warp
January 31, 2024 - A less dangerous method for undoing a git push is using the git revert command. This is because git revert will revert the changes introduced by a specific commit by creating a new opposite commit.
🌐
Reddit
reddit.com › r/github › how to "unpush" in github...?
r/github on Reddit: How to "unpush" in GitHub...?
March 31, 2025 -

Hi all,

I would appreciate any help you could give me as this is for a course. Everything makes sense. I just went too fast, and now I can't figure out how to undo it. There is a remote repository called "main" (we shouldn't touch this), then we create a "working" branch. We clone to a local repository on our computer, then start going down a checklist. I accidentally didn't switch to "working" and ended up pushing to "main" and now can't get it undone. I was instructed to delete the created "working" branch and everything cloned to my computer, but it still isn't correct. Help help!

In the screenshot, you can see where it says "2 days ago" for about.html, contact.html. and customers.html. Those should be 1 year like the rest. Graph you will also see where the changes are made to "main" and not "working". I've already deleted other branches. Thank you!

🌐
DEV Community
dev.to › github › how-to-undo-pushed-commits-with-git-2pe6
How to Undo Pushed Commits with Git - DEV Community
April 6, 2022 - Undo Pushed Commits in Git With Reset and Revert Undo Pushed Commits With the git reset Command. Undo Pushed Commits With the git revert Command.
Find elsewhere
Top answer
1 of 1
11

If I’m understanding correctly, you’re talking about a scenario like the following:

  1. You have a repo named ben3eee/some-repo
  2. You create a few commits on branch some-branch
  3. You push some-branch to ben3eee/some-repo on GitHub using git push
  4. You squash the commits into one using git rebase -i
  5. You  force push some-branch to ben3eee/some-repo on GitHub using git push -f
  6. You now want to restore some-branch to the way it was before step #4

The great thing about Git though is that it does it’s very best to never lose data, so the version of the repository before step #4 is still available as long as too much time hasn’t passed. The exact definition of “too much time” is kind of fuzzy and depends on how many other changes you’ve made between step #4 and step #6. For this example, I’m going to assume that you realize your mistake right away and no other actions were taken other than the ones in the list above.

The command that can help is called git reflog. You can enter git reflog and see all of the actions that have changed your local repository, including switching branches and rebases, going back quite a ways. I’ve created a simple reflog that shows the scenario I described above:

b46bfc65e (HEAD -> test-branch) HEAD@{0}: rebase -i (finish): returning to refs/heads/test-branch
b46bfc65e (HEAD -> test-branch) HEAD@{1}: rebase -i (squash): a
dd7906a87 HEAD@{2}: rebase -i (squash): # This is a combination of 2 commits.
a3030290a HEAD@{3}: rebase -i (start): checkout refs/heads/master
0c2d866ab HEAD@{4}: commit: c
6cab968c7 HEAD@{5}: commit: b
a3030290a HEAD@{6}: commit: a
c9c495792 (origin/master, origin/HEAD, master) HEAD@{7}: checkout: moving from master to test-branch
c9c495792 (origin/master, origin/HEAD, master) HEAD@{8}: pull: Fast-forward

You can see at HEAD@{7} I performed a checkout moving from master to test-branch. I then created three commits, “a”, “b” and “c”. Then I rebased them, arriving at HEAD@{0}. The notation HEAD@{number} is the position of HEAD at “number” changes ago. So HEAD@{0} is HEAD where HEAD is now and HEAD@{4} is HEAD four steps ago. We can see from the reflog above that HEAD@{4} is where we need to go in order to restore the branch to where it was before the rebase and 0c2d866ab is the commit ID (also sometimes called “SHA”) for that commit.  So in order to restore test-branch to the state we want, we can issue the command:

git reset --hard HEAD@{4}

Then we can force push again to restore the repository on GitHub to where it was before.

🌐
OpenReplay
blog.openreplay.com › openreplay blog › undoing git commits after push: safely revert changes on remote repositories
Undoing Git Commits After Push: Safely Revert Changes on Remote Repositories
November 30, 2024 - Use git reset to undo local commits before pushing. Use git revert to safely undo pushed commits by creating a new commit that inverts the changes.
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-undo-pushed-commits-using-git
How To Undo Pushed Commits Using Git? - GeeksforGeeks
June 27, 2024 - Modifying the most recent commit(s): The commits contain mistakes, but instead of removing them, you want to modify and then push the corrected version. Undoing older commits: There are older commits in the history that you need to remove or modify without affecting the recent commits. The git revert command is used to create a new commit that undoes the changes made by previous commits.
🌐
Laracasts
laracasts.com › discuss › channels › site-improvements › how-to-undo-a-push-in-git
How to undo a push in git?
@coder72 what branch did your commit end up on? Or have you just pushed your ProductBranch to remote and you don't want it there? if you just want to delete it, login via web to your repo (GitHub/ bitbucket) etc or manually run the following
🌐
Baeldung
baeldung.com › home › git › undo and revert commits in git
Undo and Revert Commits in Git | Baeldung on Ops
February 6, 2024 - In other words, the operation doesn’t revert to the previous state of a project by removing all subsequent commits, it simply undoes a single commit by applying its negative on the current state. This means that we should only use git revert if we want to apply the inverse of a particular commit.
🌐
DEV Community
dev.to › pierre › how-to-undo-a-git-push-force-3ijo
How to UNDO a GIT PUSH FORCE? - DEV Community
January 15, 2026 - In this session, you will see how you can use a git reset -f to restore a git push --force... Tagged with git, development, webdev, github.
🌐
Hacker News
news.ycombinator.com › item
Git commands I run before reading any code | Hacker News
April 14, 2026 - What Changes the Most · jj log --no-graph -r 'ancestors(trunk()) & committer_date(after:"1 year ago")' \ -T 'self.diff().files().map(|f| f.path() ++ "\n").join("")' \ | sort | uniq -c | sort -nr | head -20 Who Built This
🌐
Quora
quora.com › How-do-I-cancel-a-git-commit-before-push
How to cancel a git commit before push - Quora
Answer (1 of 2): You can look at show logs [code]git log [/code]take the commit hash code and then use [code]git reset --hard db0c078d5286b837532ff5e276dcf91885df2296 [/code]It is a very very high risky command as you would lose the entire work, there is a soft reset too, that resets commit bu...
🌐
DEV Community
dev.to › github › how-to-undo-pushed-commits-with-git-2pe6 › comments
[Discussion] How to Undo Pushed Commits with Git — DEV Community
Undo Pushed Commits in Git With Reset and Revert Undo Pushed Commits With the git reset Command. Undo Pushed Commits With the git revert Command.
🌐
Git
git-scm.com › docs › git-reset
Git - git-reset Documentation
However, you already dirtied the index (i.e. your index does not match the HEAD commit). But you know the pull you are going to make does not affect frotz.c or filfre.c, so you revert the index changes for these two files.
🌐
Awesome Claude
awesomeclaude.ai › code-cheatsheet
Claude Code 2.1 Cheatsheet (PDF & PNG) — Updated 2026 - Awesome Claude
June 12, 2026 - git worktree add ../myapp-hotfix -b hotfix/critical main cd ../myapp-hotfix claude "fix the critical bug" # Original work continues in main directory
🌐
Warp
warp.dev › terminus by warp › git › undo a git pull
How To Undo Pulled Commits In Git Using git-reset or git-stash | Warp
June 27, 2024 - To undo or close a pull request that has not been merged: Go to the pull request page and click on the button that says "Close pull request" Go to the repository and select the "Branches".
🌐
Git
git-scm.com › docs › git-worktree
Git - git-worktree Documentation
push · remote · submodule · show · log · diff · difftool · range-diff · shortlog · describe · apply · cherry-pick · diff · rebase · revert · bisect · blame · grep · am · apply · imap-send · format-patch · send-email · request-pull · svn · fast-import ·