• 0

Discard local file changes when checking out another branch

If you have changes in your working directory and you need to switch branches, git will complain when you attempt to checkout a different branch. A this point, you can choose one of three options:

  1. Stash your changes and then switch to another branch.
  2. Commit your changes before switching to the new branch.
  3. Disregard the changes you have (This is only for files that are also present in the branch that you are trying to check out).

Most of the times, you will find yourself juggling between option 1 and option 2. However, if option 3 is what you are looking for, the answer is simple.

git checkout -f other-branch-name

The -f stands for force.