HostOnNet Blog

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

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.

Also

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)

git

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 hostonnet2

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