0

I have a project under git. In my gitignore file, I have a folder folder/ I don't want git to care about. The problem, is each time I want to checkout a branch , I am asked to error: The following untracked working tree files would be overwritten by checkout:

error: The following untracked working tree files would be overwritten by checkout: folder/somefile folder/subfolder/somefile...

So I moved away the folder/, commited again and then took back the folder/ in my git repo. But why is this message always appearing ? (In my .gitignore, I have a line : folder/)

user1611830
  • 4,749
  • 10
  • 52
  • 89

2 Answers2

1

You are getting this message, because you committed files that are inside folder/ before adding that folder to .gitignore.

That means, although you have that folder in your .gitignore it already is inside your repository and thus will be checked out, just like all other files.

.gitignore is used when checking files in, not when checking them out.

If you want to remove folder/ from your git repository, you can do so by issuing the command git rm folder/.

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
  • hat do you mean by commited in files ? Isn't commiting a global process ? In fact what I did is that I removed folder, commited, then I took back folder/ – user1611830 Feb 05 '13 at 12:11
  • 1
    make sure you use the `--cached` flag unless you want git to remove the physical files. – cori Feb 05 '13 at 12:12
1

You've got some files/folders committed in the branch you've got checked out, presumably before you added them to .gitignore.

Remove them from your index using git rm folder\ --cached and then try again - you shouldn't receive the warning.

cori
  • 8,666
  • 7
  • 45
  • 81
  • Do you mean, when I removed folder/ then commited, my index and my working tree were still not clean ? – user1611830 Feb 05 '13 at 12:17
  • Well i's a little hard to say without knowing more about the structure of your repo, but in order to be completely clean you would have to check out each branch that "folder\" has been committed to and remove it using `git rm`. you would also need to make sure that "folder\" is in `.gitignore` in each branch - it's fairly easy to get those things out of sync, especially in a repo with a lot of branches. It sounds like in your current `HEAD` you're missing "folder\" in your `.gitignore` and in the branch you're checking out, "folder\" is still in the index. – cori Feb 05 '13 at 12:32