When I run git status
, .gitignore is listed under untracked files. How do I prevent it from being listed?
Contents of .gitignore:
images/builder/
gitignore file is showing up on the status, because it's untracked, and git sees it as a tasty new file to eat! Since . gitignore is an untracked file however, it is a candidate to be ignored by git when you put it in .
Yes, you can track the . gitignore file, but you do not have to. The main reason of having this file into repository is to have everyone working on the project, ignoring same files and folders.
Ignored files are tracked in a special file named .gitignore that is checked in at the root of your repository. There is no explicit git ignore command: instead the .gitignore file must be edited and committed by hand when you have new files that you wish to ignore. .
To clarify a bit on what others have said, there are rougly three categories of stuff that are excluded, and git uses different exclude files for each category:
Stuff that everybody working on the project wants to exclude — e.g. *.o
, the names of the generated executables, other build-generated files that you don't want to check in.
For this case, you use .gitignore
in the project directories (as you're doing). Since you want everybody working on the project to share these excludes, you should add the these .gitignore
files using git add
and commit them like source files.
Stuff that you personally want to exclude for all your projects, but others working on the same projects may not. For instance, I use the Emacs editor, which creates backup files like Foo.~1~
, so that's something I exclude personally for all my git checkouts
For this case, you use a "personal" ignore file, conventionally in your home directory called something like ~/.gitignore
; the name of this file is actually set as a global git parameter, so for instance, you might do:
git config --global core.excludesfile ~/.gitignore
[As that's a global setting, you only need to do it once.]
So for my Emacs backup files, I add a pattern like *~
to ~/.gitignore
.
Stuff that you want excluded "locally" in a specific working-tree, but maybe not for other working-trees.
For this case, you should add exclude entries to the .git/info/exclude
file. Since this file is underneath the magic .git
directory, the status command will never show it as an untracked file (and you can't add it).
Git uses all these exclude files together to decide what's excluded.
You can add .gitignore
to your .gitignore
file, but you probably just want to commit it anyway considering all of your team members (if there are any others) are probably going to have the same files listed in .gitignore
.
Just commit the file.
It will then go away from the list.
(I found this confusing initially.)
You'll still be able to edit it to add more items in the future.
And then commit again to ignore them
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With