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?

3

5 Answers 5

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]
*~
2
  • What do you mean by "files that no one else sees"?
    – freitass
    Jun 9, 2011 at 15:44
  • Files that are local to your setup; for instance you may have a utility script in your working tree that is not tracked by git and only you can see. Jun 9, 2011 at 15:47
16

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

2
  • sorry, how do i do this? I don't have access to the main git account.
    – JDesigns
    Jun 9, 2011 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 9, 2011 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

1
  • 3
    gitignore lines are not regular expressions, but rather more like shell globs. Dec 28, 2011 at 16:13
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!

1
  • beware, git clean will remove the files from hdd! but its working. :)
    – csomakk
    Mar 12, 2013 at 14:49
7

If you want to do this globally all the time do

git config status.showuntrackedfiles no
1
  • 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. May 3, 2023 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.