1

I am working on windows. Using Git I am trying to switch to another local branch but it won't let me due to this error:

Your local changes to the following files would be overwritten by 
checkout:
codelibrary/inc/variables.php 

But when I do git status on my current branch, I get:

nothing to commit, working tree clean

I've seen 2 questions that are the same as mine in these links:

  1. git status shows modifications, git checkout -- <file> doesn't remove them
  2. can't checkout a git branch - need to commit changes, but no changes are present

But none of the answers seem to solve my problem.

I suspect I had the file ignored in my current branch but not in the branch I want to switch to.

I'm new to git so I would like to ask the git pros to please help me with this.

Ian Jay
  • 82
  • 1
  • 2
  • 11
  • 1
    Try `git ls-tree -r -t HEAD | grep -i codelibrary/inc/variables.php` to see if there are multiple files with the same name except that the letter case is different. – ElpieKay Apr 13 '19 at 03:58
  • Hi @ElpieKay, thanks for your reply, I tried your suggestion and got this: 100644 blob 51048fd3e109fc8353d9aeccb8732d552f4755d1 codelibrary/inc/variables.php But I don't know what that means – Ian Jay Apr 13 '19 at 04:15
  • Then try `git check-ignore codelibrary/inc/variables.php` to see if it's really ignored. – ElpieKay Apr 13 '19 at 04:19
  • 1
    I suspect your suspicion is correct :) Suggest renaming it temporarily. – Ry- Apr 13 '19 at 04:23
  • It is ignored ElpieKay. – Ian Jay Apr 13 '19 at 08:04
  • I'll try that suggestion @Ry-, thanks. – Ian Jay Apr 13 '19 at 08:05
  • Hi @Ry-, I tried renaming the file, but I still receive the same error. I don't know what's happening anymore. – Ian Jay Apr 13 '19 at 12:23
  • Nevermind, I'm so dumb, I renamed the file in a wrong path, Thanks @Ry- and ElpieKay. – Ian Jay Apr 13 '19 at 12:26

1 Answers1

4

This happens when you have an untracked file in your path which is tracked in the branch you try to checkout. Git will not know what to do with this file (which one to use between the tracked and the untracked one, so it refuses to checkout the branch.

padawin
  • 4,230
  • 15
  • 19