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
The git checkout -b <BranchName> command will create a new branch and switch to it. Moreover, this command will leave the current branch as it is and bring all uncommitted changes to the new branch.
You must commit or stash those changes first before switching branches. You can think of stash as a drawer to store uncommitted changes temporarily.
Before you commit your changes reside on disk (the "working copy") or after you git add the "staging area". Neither of these belong to a particular branch. When you switch branches, uncommitted changes will go with you. If changing a branch would overwrite your uncommitted changes, Git will not let you switch.
Option 1
git checkout -f gh-pages
Option 2
git reset --hard # beware: don't make that a habit git checkout gh-pages
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With