16

When I run git status, I see the "Untracked files" section has many files (some with a "." extension.)

I don't think I have to do anything, but it doesnt look good to see these files whenever I run git status. Is there any way to not to see these files?

200_success
  • 7,286
  • 1
  • 43
  • 74
JDesigns
  • 2,284
  • 7
  • 25
  • 39
  • possible duplicate of [.gitignore - ignore any 'bin' directory](http://stackoverflow.com/questions/1470572/gitignore-ignore-any-bin-directory) – manojlds Jun 09 '11 at 15:44
  • 1
    More likely a duplicate of http://stackoverflow.com/questions/11542687/git-how-to-ignore-all-present-untracked-files – Diego Feb 28 '13 at 17:40
  • Possible duplicate of [git: How to ignore all present untracked files?](https://stackoverflow.com/questions/11542687/git-how-to-ignore-all-present-untracked-files) – The Bearded Llama Aug 18 '17 at 08:56

5 Answers5

21

Files that are "yours", files that no one else sees, write in .git/info/exclude.

For files that everyone else sees, write them down in .gitignore at the project top directory and then add and commit the .gitignore file.

For example, your .gitignore might look like so:

*.o
.*.sw[op]
*~
wilhelmtell
  • 57,473
  • 20
  • 96
  • 131
16

You need to create one or several .gitignore files. They can be stored in git itself, or just kept local.

sam hocevar
  • 11,853
  • 5
  • 49
  • 68
  • sorry, how do i do this? I don't have access to the main git account. – JDesigns Jun 09 '11 at 15:49
  • 3
    @Jay Just do it. You don't have to have access to the "main git account", whatever that is. Just create a file called ".gitignore" and start putting things in it. – user229044 Jun 09 '11 at 16:20
14

You can make git ignore all files that match a regular expression (like all files *.ext) by adding the line *.ext in file .git/info/exclude.

Added Abe Voelker's comment bellow to improve the answer:

Note that this approach is local to your repository. If you ever clone it (e.g. share it with others), your ignore settings will not be pulled in.

If you need to share the ignore settings, you should put it in .gitignore files

rambo
  • 418
  • 4
  • 16
10

To ignore, use .gitignore, as Sam Hocevar said.

To delete, you'll probably want to do a git clean, which will clean up any files that aren't tracked by git. You might need to use the -f and -d switches if you've got directories which aren't tracked.

Be careful with git clean, it will delete things you haven't added to git yet!

James Gregory
  • 14,173
  • 2
  • 42
  • 60
7

If you want to do this globally all the time do

git config status.showuntrackedfiles no
eludom
  • 477
  • 5
  • 6
  • This will only change for the current repository. If you want to do this globally as for all the repository on your machine for this user, use --global after config. For all user, use --system. – Mister Someone May 03 '23 at 11:42