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.

Ryan Sukale

Ryan is just a regular guy next door trying to manage his life and finances.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *