Be aware that this will create an "alternate reality" for people who have already fetched/pulled/cloned from the remote repository. But in fact, it's quite simple:

git reset HEAD^ # remove commit locally
git push origin +HEAD # force-push the new HEAD commit

If you want to still have it in your local repository and only remove it from the remote, then you can use:

git push origin +HEAD^:"$name_of_your_branch" # e.g. +HEAD^:master

Some shells interpret the ^ character. For those shells, either quote/escape or use ~:

HEAD\^
'HEAD^'
HEAD~
Answer from knittl on Stack Overflow
🌐
Reddit
reddit.com › r/git › how can i completely delete commits from both local and remote?
r/git on Reddit: How can I completely delete commits from both local and remote?
May 11, 2020 -

Hi there –

I've made a complete mess of my repo. Three branches are now in an unreliable state.

Unfortunately, much of the mess is already on GitHub.

I'd like to completely delete all commits that were made after a certain point, so that I can start over with a clean slate.

How can I do this, in a way that will also delete the problematic commits from GitHub?

Unfortunately, I'm not a very proficient Git user – so anything about rebasing, reflogs, etc. is going to lose me very quickly. Please, speak slowly and use small words :)

Thanks for any suggestions.

ETA: I found this StackOverflow answer, which recommends doing git reset --hard <last_working_commit_id> to delete the bad commits, and then using git push --force to delete them from GitHub. This sounds easy, but is there anything I should consider before using this technique?

Discussions

Delete last Git commit from local and remote repositories.
Delete last Git commit from local and remote repositories. Need to delete the last (and only) commit from both local and remote repositories. I created a branch (call it dev-branch) and made a change to a file. Then I added, then committed the change locally. Then I pushed the commit to the remote repository. It has NOT been merged. I want to basically start over - remove ... More on experts-exchange.com
🌐 experts-exchange.com
August 1, 2022
How to delete commit from GiHub and remove it from SourceTree ?
git checkout HEAD~2 --hard git push --force More on reddit.com
🌐 r/github
1
1
July 3, 2018
Removing file from the latest commit
Actually, either approach will work. The approach in that StackOverflow post (of using git reset --soft HEAD^) will work. It will destroy the commit, sort of reversing the state of things back to like before you committed it, and then you can create a new, replacement commit after making changes (in your case deleting a file). The approach in the Medium post can work, too, if you do it right. There's an implied step (between 4 and 5), which is to run git commit. Normally, that will create an additional commit, whereas what you want to do is replace the commit you just created. But you can do that by running git commit --amend instead. More on reddit.com
🌐 r/git
10
6
January 17, 2021
How do I undo the most recent local commits in Git? [Tutorial]
git reset**:** This allows you to move the HEAD to a specific state, effectively undoing commits while keeping your changes staged or unstaged. Just remember to use it carefully, as it can alter your commit history. git restore**:** this provides a simpler way to undo changes in the working directory and staging area introduced by the most recent commit. It's a handy tool for reverting changes quickly. git revert**:** If you've already pushed your commits to a remote repository and want to undo them without altering history, git revert is a safe option. It creates a new commit that undoes the changes made in a specified commit. git checkout**:** While primarily used to switch branches, git checkout can also help you undo local commits by moving the HEAD pointer to a previous commit. It's useful for discarding the most recent commit. git commit --amend**:** If you only need to modify the commit message of your most recent commit, this command comes in handy. It allows you to edit the commit message without creating a new commit. Or the solution I've adopted a while ago and never looked back, lol, is cmd+z from Tower , their undo command is pure magic. More on reddit.com
🌐 r/git
3
0
May 1, 2024
🌐
HackerNoon
hackernoon.com › how-to-delete-commits-from-remote-in-git
How to Delete Commits From Remote in Git | HackerNoon
May 31, 2022 - [ ]Save and exit (you may need ... the rebase. To delete commits from remote, you will need to push your local changes to the remote using the git push command....
🌐
Experts Exchange
experts-exchange.com › questions › 29244073 › Delete-last-Git-commit-from-local-and-remote-repositories.html
Solved: Delete last Git commit from local and remote repositories. | Experts Exchange
August 1, 2022 - You can also use git reset · git reset --soft or git reset --mixed or git reset --hard · Select allOpen in new windowBut this command is more dangerous, and I wouldn't recommend using it unless you really have to.
🌐
Medium
medium.com › @bsalwiczek › 4-ways-to-remove-changes-from-remote-branch-in-git-8634fc7b397a
4 Ways to Remove Changes From Remote Branch in GIT | by Bartosz Salwiczek | Medium
April 13, 2022 - The easiest approach to remove it is to reset git head to the previous commit. To do that use: ... Now commit is removed from your local branch. All we need to do is push changes to the remote repository:
🌐
GitButler
gitbutler.com
GitButler
GitButler software development platform
Find elsewhere
🌐
Warp
warp.dev › terminus by warp › git › undoing git commits
How To Undo Your Last Git Commit(s) | Warp
November 30, 2023 - If you decide to use git reset or git checkout to overwrite commits, then you can use git push --force to overwrite the remote branch with your local branch. This will overwrite any commits that were made after your last pull.
🌐
GitHub
gist.github.com › vishaltelangre › 5531806
Revert last local or remote commit (git) · GitHub
Save vishaltelangre/5531806 to your computer and use it in GitHub Desktop. ... There are two ways to "undo" your last commit, depending on whether or not you have already made your commit public (pushed to your remote repository): ##How to undo a local commit Lets say I committed locally, but now want to remove ...
🌐
Codemia
codemia.io › knowledge-hub › path › remove_last_commit_from_remote_git_repository
Remove last commit from remote Git repository
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises
🌐
Adamdurrant
adamdurrant.co.uk › blog › undo-git-commit
How to Undo Pushed Git Commits Locally & Remotely<!-- --> | ADurrant
Now that you have got your local ... a removal of the your last commit): $ git push origin HEAD --force-with-lease Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0) To ......
🌐
Git Tower
git-tower.com › learn › git faq › how to undo, revert, or delete a git commit
How to Undo, Revert, or Delete a Git Commit | Learn Version Control with Git
Change pick to drop next to the commit you want to remove, then save and close: Because this rewrites history, a force-push is required afterward if the commits are already on a remote. Only use interactive rebase on private branches that haven't been shared with others. In case you are using the Tower Git client, interactive rebase is accessible directly from the right-click menu, and if you make a mistake, you can undo it with CMD+Z:
Published   6 days ago
🌐
TecAdmin
tecadmin.net › git-delete-last-x-commits
Git Command to Delete Last 5 Commits
April 26, 2025 - To delete a commit, change the word “pick” at the beginning of the line to “drop”. Save and close the file. ... If there are conflicts during the rebase, you will need to resolve them.
🌐
CSDN
cnblogs.com › xgqfrms › p › 15942928.html
git delete the latest commit from remote branch All In One - xgqfrms - 博客园
February 27, 2022 - git delete the latest commit from remote branch All In One # remove commit locally $ git reset HEAD^ # force-push the new HEAD commit $ git push origi
🌐
freeCodeCamp
freecodecamp.org › news › git-remove-last-commit-how-to-undo-a-commit-in-git
Git Remove Last Commit – How to Undo a Commit in Git
September 21, 2022 - After that, use the following command to undo the commit: ... Now, let's use git log again. You should see the commit hash, and a (HEAD -> main, origin/main) at the end. The last commit you made is no longer part of the repository's history ...
🌐
Git Skills
smartgit.dev › git-how-to › undo-last-commit
How to Undo Last Git Commits | Git Skills
If you still wish to undo the bad commits, you will need to force-push the current branch. Undoing One Single Commit: To undo just the latest commit, simply invoke Local | Undo Last Commit. This will move the changes from the bad commit ...
🌐
Git
git-scm.com › book › en › v2 › Git-Branching-Basic-Branching-and-Merging
Git - Basic Branching and Merging
This is an important point to remember: when you switch branches, Git resets your working directory to look like it did the last time you committed on that branch. It adds, removes, and modifies files automatically to make sure your working copy is what the branch looked like on your last commit ...
🌐
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 - git reset --hard HEAD~1: This command discards all changes from the last commit, effectively removing it from your repository. Use this with caution, as it permanently deletes the changes.
🌐
H3rald
h3rald.com › grimoire › remove-last-git-commit
Remove your last git commit - H3RALD
Undoing the last git commit is easy enough, thankfully. If you didn’t push already, just run ... If you did push to your remote repository, but hopefully no one else pulled already, you can run the following command after the previous one:
🌐
Graphite
staging-graphite-splash.vercel.app › guides › how-to-remove-a-file-from-a-git-commit
How to remove a file from a Git commit
Find the commit containing the file you want to remove and change pick to edit. Save and close the editor. Git will pause the rebase at the commit you chose to edit. ... If you've already pushed the commit to a remote repository, the process is similar to the above, but requires force-pushing to re-write the history of the branch:
🌐
Shkodenko Taras
shkodenko.com › home › server configuration › git › how to undo a commit, pull remote changes, and reapply your work in git
How to Undo a Commit, Pull Remote Changes, and Reapply Your Work in Git | Shkodenko Taras
December 30, 2024 - If you want to completely undo the commit and unstage the changes, use: ... Warning: Using --hard will delete your changes permanently. ... Ensure you know the correct remote you want to pull from (e.g., origin). If you have multiple remotes, double-check which one is appropriate for your changes. To pull the latest changes from the correct remote and branch, run: ... If there are conflicts, Git will prompt you to resolve them manually.