Note: please see an alternative to
git rebase -i
in the comments below—
git reset --soft HEAD^
First, remove the commit on your local repository. You can do this using git rebase -i
. For example, if it’s your last commit, you can do git rebase -i HEAD~2
and delete the second line within the editor window that pops up.
Then, force push to GitHub by using git push origin +branchName --force
See Git Magic Chapter 5: Lessons of History – And Then Some for more information (i.e. if you want to remove older commits).
Oh, and if your working tree is dirty, you have to do a git stash
first, and then a git stash apply
after.
Related Posts:
- Differences between Commit, Commit and Push, Commit and Sync
- Git: Message ‘src refspec master does not match any’ when pushing commits in Git
- Git: Message ‘src refspec master does not match any’ when pushing commits in Git
- How do I undo the most recent local commits in Git?
- How can I switch to another branch in git?
- GitHub: Permission denied (publickey). fatal: Could not read from remote repository
- How to modify existing, unpushed commit messages?
- git – remote add origin vs remote set-url origin
- Git: Message ‘src refspec master does not match any’ when pushing commits in Git
- GitHub Error Message – Permission denied (publickey)
- Updating a local repository with changes from a GitHub repository
- Git push results in “Authentication Failed”
- github changes not staged for commit
- Git : fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists
- Git push results in “Authentication Failed”
- Download single files from GitHub
- How do I pull my project from github?
- Remove files from Git commit
- Difference between Git and GitHub
- How to solve SSL certificate: self signed certificate when cloning repo from github?
- How do I resolve git saying “Commit your changes or stash them before you can merge”?
- How do I resolve git saying “Commit your changes or stash them before you can merge”?
- How to find my GitHub username so that I can be found via the URL?
- Pushing empty commits to remote
- github website publish cannot publish unborn HEAD
- fatal: The current branch master has no upstream branch
- How do I resolve git saying “Commit your changes or stash them before you can merge”?
- Create a tag in a GitHub repository
- Git: Could not resolve host github.com error while cloning remote repository in git
- How to pull a specific branch from Github
- GitHub: invalid username or password
- Trying to git pull with error: cannot open .git/FETCH_HEAD: Permission denied
- How do I update or sync a forked repository on GitHub?
- Can I share my private GitHub repository by link?
- There is no tracking information for the current branch
- Git push results in “Authentication Failed”
- Meaning of the GitHub message: push declined due to email privacy restrictions
- How to rename a directory/folder on GitHub website?
- “*** Please tell me who you are.” when using SSH key
- How to undo git reset –soft to get my changes back?
- Download a single folder or directory from a GitHub repo
- Pull request vs Merge request
- Clone A Private Repository (Github)
- How do I rename a repository on GitHub?
- git status (nothing to commit, working directory clean), however with changes commited
- error: cannot lock ref.. ‘refs/tags’ exists; cannot create ‘refs/tags/
- Git: Installing Git in PATH with GitHub client for Windows
- ! [rejected] master -> master (fetch first)
- How to git add a whole folder
- My new Github page isn’t showing up
- Unity Collaborate vs GitHub
- What are the differences between “git commit” and “git push”?
- “fatal: HttpRequestException encountered.” Error with GitHub/Bitbucket Repositories due to dropping TLS-1.0 support
- SourceTree keeps asking for Github password
- How do I set up Eclipse/EGit with GitHub?
- Repository size limits for GitHub.com
- How to change the license for a project at Github?
- Why I always Got Error “Push to origin/master was rejected”?
- Git lfs – “this exceeds GitHub’s file size limit of 100.00 MB”
- Github Windows ‘Failed to sync this branch’
- fatal: could not read Username for ‘https://github.com’: No such file or directory
- Github Authentication Failed – … GitHub does not provide shell access
- How to update a branch with master on GitHub
- How do I pull files from remote without overwriting local files?
- Git keeps prompting me for a password
- git push origin master does not work
- Can I arrange repositories into folders on Github?
- Delete forked repo from GitHub
- Found a swap file by the name
- Git – Remove commit from history
- How to discard local changes and pull latest from GitHub repository
- Could not create work tree dir ‘example.com’.: Permission denied
- How can I delete all Git branches which have been merged?
- key_load_public: invalid format
- Git push hangs when pushing to Github?
- Git: Where exactly is the “working directory”?
- Create empty branch on GitHub
- Import existing source code to GitHub
- Git push requires username and password
- GIT and Development URL’s point to production
- Pull latest stable release via git [closed]
- Is it possible to checkout a beta version of WordPress via github?
- how can I create a WP offline environment before releasing the websites? [closed]
- error: src refspec master does not match any
- Git error: “Please make sure you have the correct access rights and the repository exists”
- Undoing a git rebase
- How to resolve merge conflicts in a Git repository
- How can I delete a file from a Git repository?
- Make an existing Git branch track a remote branch?
- How do you create a remote Git branch?
- What is the difference between `git merge` and `git merge –no-ff`?
- The following untracked working tree files would be overwritten by merge, but I don’t care
- “git checkout
” is changing branch to “no branch” - Does Git Add have a verbose switch
- How do I list all of the files in a commit?
- How do I run git log to see changes only for a specific branch?
- Difference between git stash pop and git stash apply
- How do I show the changes which have been staged?
- Is Git/GitHub a good WordPress deployment solution?
- How to retrieve the last modification date of all files in a Git repository