Switching a branch after aborting current changes in git

highBandWidth picture highBandWidth · Sep 18, 2011 · Viewed 57.9k times · Source

I cloned a git repo and then started playing around in its master branch. After a while, I want to ignore the changes I just made (without committing them), and switch to a different branch. However, it stops me from switching because there are uncommitted changes. How do I ignore them without stashing them either? This is what happens:

$ git checkout gh-pages
error: Your local changes to the following files would be overwritten by checkout:
        somefile.txt
Please, commit your changes or stash them before you can switch branches.
Aborting

Answer

sehe picture sehe · Sep 18, 2011

Option 1

git checkout -f gh-pages

Option 2

git reset --hard     # beware: don't make that a habit
git checkout gh-pages