How To Fix Git Error Your Local Changes To The Following Files Would Be Overwritten By Merge When Pull Commits From Remote Repository

My project use SourceTree to push and pull commits from a git repository. When I pull a remote commit, I meet an error message like this: Your local changes to the following files would be overwritten by merge, Please commit your changes or stash them before you merge.

 * branch              master     -> FETCH_HEAD
error: Your local changes to the following files would be overwritten by merge:
    PythonExampleProject/.pydevproject
    PythonExampleProject/com/.../mongo/MongoDBConnect.py
Please commit your changes or stash them before you merge.
Aborting
Updating 31bddd97..ea752301
Completed with errors, see above

After investigating, I finally find the method to fix this error, and the pull remote commits action perform successfully. Below are the steps.

  1. Select the files in SourceTree which are not committed to the repository remote server.
  2. Right-click the uncommitted files and click the Reset to Commit… menu item in the popup menu. This menu item will discard those not pushed committed changes.
  3. If you have removed the above-uncommitted files, it will pop up a dialog window that lets you select the commit which you wish to revert the selected files to, you can select a commit in this dialog.
  4. Click the OK button in the next 2 popup dialog. Then you can click the pull icon in the top SourceTree toolbar to pull commits from the remote repository server.

Subscribe to receive more programming tricks.

We don’t spam!

Subscribe to receive more programming tricks.

We don’t spam!

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.