Git remove remote history past certain commit


I have a Git/Gitlab repository. We used to commit straight to master, but we decided to switch to using feature branches like the rest of the world for this release.

We need to reset our remote master to the state it was in immediately after the last release. If someone has already committed to the master directly, how can I reset it to a clean state, removing all history past the last release?

I’ve spent about an hour googling now and can’t find an answer to this specific question. Sorry if it seems redundant, it seems like such a simple task with no obvious answer!


To reset a local branch,

git branch -f master last-release

To reset a remote branch,

git push -f origin last-release:master

where last-release is the ref (commit id or branch) you want to reset master to.

(Neither of these affect your working tree; you can even do these from a bare repo, if you wish.)

Answered By – Paul Draper

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published