Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git fails because of an untracked working tree file

I'm not an expert at google. Needless to say, I'm not even sure what this means or how to resolve it?

>> git merge admin_playground
error: Untracked working tree file 'vendor/gems/panda-1.0.0/.gitignore' would be overwritten by merge.
fatal: merging of trees 538b2824765956cc44c42a8ad628e4f4 and d5d4cda68518cd1c81bf70ba8c339fea6 failed

I am trying to perform a git merge and getting this failing statement.

like image 677
Trip Avatar asked Dec 16 '10 15:12

Trip


People also ask

Could not merge the following untracked working tree files would be overwritten by merge?

The reason of getting this error:” the following untracked working tree files would be overwritten by merge” is that you're not tracking the files locally but there might be a chance that the identical files are tracked by the remote.

How do I stop untracked files in git?

Git can only ignore files that are untracked - files that haven't been committed to the repository, yet. That's why, when you create a new repository, you should also create a . gitignore file with all the file patterns you want to ignore.

Why do I have untracked files in git?

Untracked files are those that are in the repo's directory but have not yet been added to the repo's index with git add .


3 Answers

It's because .gitignore isn't in your current branch (it's untracked), but it's in the branch you're trying to merge. Add the .gitignore file in question and commit, then try the merge again; or delete the .gitignore file if you don't need it and are happy with the one in the other branch.

like image 53
mipadi Avatar answered Oct 02 '22 12:10

mipadi


Note: mipadi (author of the accepted answer) also mentioned this error message in the context of case conflicts between filenames on different branches.

If cleaning the untracked files is a valid option, then the extreme solution is mentioned in this answer (a git clean -f -d would remove all untracked files and directories).
In your case, that could be overkill (or dangerous).

Another original solution:

git checkout -f admin_playground # will overwrite files
git checkout yourBranch # get back where you where when trying the merge
git merge admin_playground

This forced git to go ahead and overwrite the files.
I assume you could have used the '-f' option with merge also, but switching to the other branch and then back fixed the issue and I was able to merge without any trouble the next time.

Note: there is actually no '-f' option on git merge.

like image 30
VonC Avatar answered Oct 02 '22 12:10

VonC


Try running below commands :

git add *

git stash

git pull
like image 21
kintu david Avatar answered Oct 02 '22 13:10

kintu david