Farzan Ali Shaikh Farzan Ali Shaikh - 3 years ago 165
Git Question

Unable to switch branches in git, shows error: The following untracked working tree files would be overwritten by checkout

When i make some changes to a branch and try switching to the master branch I keep getting this error: The following untracked working tree files would be overwritten by checkout

The solutions on this thread dont work: The following untracked working tree files would be overwritten by checkout

enter image description here

Answer Source

My guess as to what is causing this error is that the files listed in your error are untracked in your current searchPlus branch, but they are tracked in your master branch. If Git were to checkout master blindly, it would clobber (i.e. overwrite) these files. When Git checks out another branch it overwrites every tracked file. Normally, if the file being overwritten is already being tracked, there is minimal risk because you still have the other branch somewhere. However, in the case of your untracked files, it would overwrite them, and you would therefore lose the state these files had on searchPlus. To make matters worse, after checking out master, if you were to return to searchPlus, these files would actually disappear because Git would determine that these files do not exist in your searchPlus branch.

To get around this, one possible solution would be to just git add these files and make a commit. Assuming they were already committed in master, perhaps it makes sense for these files to be versioned everywhere.

As a side note, those .project files in your error message look suspicious to me. Typically, configuration files should not be versioned by Git, so you might want to see whether you really even want them versioned in the master branch.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download