Discard local file changes when checking out another branch

If you have changes in your work­ing direc­tory and you need to switch branches, git will com­plain when you attempt to check­out a dif­fer­ent branch. A this point, you can choose one of three options:

  1. Stash your changes and then switch to another branch.
  2. Com­mit your changes before switch­ing to the new branch.
  3. Dis­re­gard the changes you have (This is only for files that are also present in the branch that you are try­ing to check out).

Most of the times, you will find your­self jug­gling between option 1 and option 2. How­ever, if option 3 is what you are look­ing 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 *