Search code examples
gitgithubphpstorm

Git cannot pull, commit stash or revert changes


When trying to pull with git I constantly get this error:

"Your local changes would be overwritten by merge. Commit, stash or revert them to proceed. "

I have looked for this error on multiple sites including StackOverflow. If I view the files which cause a conflict, I see that it is about files which are not in my github repo. They are local files.

As far as I know the only way to keep all my local files and pull the rest from git is by using commit (based on the options stash, commit or revert). I did this but I still get the same error.

I haven't added those local files to my github repo though, but I want to keep these files local, so as far as I know I should not do this.

I am using PhpStorm's built in git feature. I know there are questions on StackOverflow with the same error. I tried most of these solutions however, and it didn't work for me.


Solution

  • If you just want to brute force reset followed by a git pull to update, you can do:

    git reset --hard
    

    and then try pulling again. This will totally clear out your uncommitted changes. Only do this if that's really what you want to do.

    If you still have errors after that, maybe you have some local files that would be overwritten by the pull. You can clear them all out with the command:

    git clean -f
    

    Although again, you want to be careful that you actually want these files removed. Once you git clean you cannot undo it. To be sure, inspect your current state using:

    git status