Reverting GitHub master branch to a particular commit ( discard everything after that )


0

Sometimes you may want to reset your master branch to a particular commit. Lets say by mistake you have committed sensitive credentials, if you made another commit by removing them still they will stay in your GitHub history. In the cases you can opt for resetting your master branch to a valid commit by following below mentioned steps.

1. Find out the commit you want to rest to

Goto commits tab on your master branch and pick the commit you want to revert to.
For example lets say i picked 801feed as shows in below image.

2. Run git reset --hard command

Run the following command to reset to 801feed


3. Push the current state to remote

Now you need to push the current state of your git repo to master, you can do that by running the following command


Thats it! Now if you goto master brach's commits, you will see your last commit as the commit you reset to. All the commits after that will be gone.