Skip to main content

GIT Error: The following untracked working tree files would be overwritten by merge:

Recently I renamed following file names(changed only captal to simple) and added to branch(abc) and commited them.
I pushed the branch as well. 
app/SocialMedia/EmailShare.php --> app/SocialMedia/Emailshare.php
        app/SocialMedia/EmailShareFactory.php ---> app/SocialMedia/EmailshareFactory.php

After that I tried to checkout a different branch(beta). Accidently git throws following error.

$ git checkout beta
error: The following untracked working tree files would be overwritten by checkout:
        app/SocialMedia/EmailShare.php
        app/SocialMedia/EmailShareFactory.php
Please move or remove them before you can switch branches.
Aborting

But when applying git status command no files to commit

$ git status
On branch abc
nothing to commit, working directory clean

Finally I checkout master branch. It was succefull. I think, because those files are still not in the master branch.

After that I was able to checkout beta branch as well. Now that error happens again when I'm going to merge a branch to beta branch. Then I used gitlab to merge. It was successfull. Then I tried to pull beta branch in command line. It gives an error again.

==========================================================================================
Solution


1. Fetch all

git fetch --all

2. Reset to beta branch

git reset --hard origin/beta

Comments