how to discard git local branch changes?
Solution 1:
If you have uncommitted changes that you want to discard, use this:
$ git reset --hard
which is equivalent to
$ git reset --hard HEAD
This removes all the local uncommitted changes. If you want to remove some offending commits from your local branch, try rewinding it:
$ git reset --hard HEAD^ #moves HEAD back by one commit
or e.g.
$ git reset --hard HEAD~3 #moves HEAD back by 3 commits
Use these with caution, as you won't be able to undo these operations. Once you're done cleaning up your local branch, use git pull
to get the latest code.
Solution 2:
git fetch
git reset --hard origin/master
Solution 3:
Have you already commited your local changes? If not a git reset --hard HEAD should do the trick