How do I resolve git saying “Commit your changes or stash them before you can merge”?

You can’t merge with local modifications. Git protects you from losing potentially important changes.

You have three options:

  • Commit the change usinggit commit -m "My message"
  • Stash it.Stashing acts as a stack, where you can push changes, and you pop them in reverse order.To stash, typegit stash Do the merge, and then pull the stash:git stash pop
  • Discard the local changesusing git reset --hard
    or git checkout -t -f remote/branchOr: Discard local changes for a specific fileusing git checkout filename

Leave a Comment