Josiah Sprague Josiah Sprague - 2 months ago 5
Git Question

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

I made some updates on my local machine, pushed them to a remote repository, and now I'm trying to pull the changes to the server and I get the message;

error: Your local changes to the following files would be overwritten by merge:
Please, commit your changes or stash them before you can merge.

So I ran
git checkout -- wp-content/w3tc-config/master.php
and tried again and I get the same message. I'm assuming that w3tc changed something in the config file on the server. I don't care whether the local copy or remote copy goes on the server (I suppose the remote one is best), I just want to be able to merge the rest of my changes (plugin updates).

Any ideas?


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

You have three options.

1. Commit the change using

    git commit -m "My message"

2. Stash it.

Stashing acts as a stack, where you can push changes, and you pop them in reverse order.

To stash type:

git stash

Do the merge, and then pull the stash:

git stash pop

3. Discard the local changes

using git reset --hard.