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:
- Stash your changes and then switch to another branch.
- Commit your changes before switching to the new branch.
- 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.