211

I'm using git status -u to show untracked files. And on the terminal, I see plenty untracked files that I need to be untracked such as unit tests, personal documentation, etc. I have put them in .gitignore, but it seems that git status still shows them.

How do you show only untracked files that don't exist in .gitignore.

Ross Rogers
  • 23,523
  • 27
  • 108
  • 164
justjoe
  • 5,454
  • 9
  • 44
  • 64
  • 11
    if untracked files are shown in git status, they are not ignored by .gitignore properly. can you show you working directory structure and .gitignore contents? – max Aug 21 '10 at 16:45
  • 7
    Agree with @max, it should work. Here's a wild guess: if you're on Windows, be aware that .gitignore, unlike Windows, is case-sensitive. So if you ignore *.txt and there's a Test.TXT on disk, it won't be ignored. – Joe White Aug 21 '10 at 16:48

3 Answers3

359

You can explicitly list what is being tracked and untracked as follows to see if Git is seeing and honoring your .gitignore. If you post your .gitignore contents, git status output, and dir or ls we can better assist you.

List ignored files

$ git ls-files . --ignored --exclude-standard --others

List untracked files

$ git ls-files . --exclude-standard --others
mikemaccana
  • 110,530
  • 99
  • 389
  • 494
Matthew McCullough
  • 17,160
  • 7
  • 39
  • 38
  • 4
    If you see files that you didn't think were in your .gitignore, there may be another one hiding in your project. Ferret it out with ` find . -name .gitignore`. – jpadvo Dec 10 '13 at 20:54
  • @matthew-mccullough Great answer! I'll be adding some aliases for these thanks! @jpadvo Can you give example of useage for `find` method? – lacostenycoder Dec 18 '16 at 09:19
  • 1
    If you want a short list, say you're ignoring node_modules and don't want to see the whole tree, add `--directory` so only the top-level folder being ignored will be printed (this is closer to git status). – Henry Blyth Apr 10 '17 at 12:20
  • 2
    To make it clear, `git ls-files --others --exclude-standard --ignored` lists untracked ignored files, and `git ls-files --others --exclude-standard` untracked not ignored ones. More on it [here](https://gist.github.com/x-yuri/06fc5dc1b8804f1204e4d615fd0d6b51). – x-yuri Nov 17 '18 at 01:47
  • 1
    Note that by default `git ls-files --others` does not list empty directories. To list empty directories add the `--directory` option. This is not obvious from the man page but can be deduced. `--directory`: _If a whole directory is classified as "other", show just its name (with a trailing slash) and not its whole contents._. `--no-empty-directory`: _Do not list empty directories. Has no effect without --directory._ – el_tigro May 02 '19 at 04:58
-8

Use:

git config status.showuntrackedfiles no 
Tim Post
  • 33,371
  • 15
  • 110
  • 174
Ohad Sadan
  • 877
  • 6
  • 15
-8
git update-index --no-assume-unchanged <file>
M Khalid Junaid
  • 63,861
  • 10
  • 90
  • 118