Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Remove all local commits in git

I’ve come back to a project that I haven’t visited for a while. I did git pull and git config pull.rebase false (maybe I shouldn’t have), but got something like this after git status:

On branch develop
Your branch is ahead of 'origin/develop' by 27 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

I only want to have tha same code as develop and nothing else. What can I do to remove all commits locally and just have the same code as remote develop?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

To reset your branch to the remote’s state and remove all your commits that are not pushed yet (I believe that’s what you want to do) :

git reset --hard origin/<branch>

So in this case it would be :

git reset --hard origin/develop

Be careful with this as you would lose all of those commits !

If you want to keep a copy just in case, you could clone your repository in another folder and start working from there, keeping your unpushed commits just in case.

git clone <your repo>/develop
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading