HostOnNet Blog

How to discard local commits in Git without local directory deletion or redownload

Looking for Linux Server Admin or WordPress Expert? We can help.

I have modified something in my local branch and but the changes not looking good.

So I just tried by pulling the files from remote server using following command

git pull origin master

Nothing has happend and my local branch remains same as old.


git checkout master 

Showing like

Switched to branch ‘master’
Your branch is ahead of ‘origin/master’ by 3 commits.
use “git push” to publish your local commits)


I did some research and got the following

git reset --hard origin/master

After running the same, it worked.

NB:(Only for beginners like me 🙂 If you are an expert in git, just share your experience also

About Sibi Antony

Bootstrap and Android LOVER. I've been creating things for the web for over 10 years, from the period of flash and table based layout web sites till mobile and tab friendly web sites.
Posted in Git

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.