I just did a git init
on the root of my new project.
Then I created a .gitignore
file.
Now, when I type git status
, .gitignore file appears in the list of untracked files. Why is that?
I just did a git init
on the root of my new project.
Then I created a .gitignore
file.
Now, when I type git status
, .gitignore file appears in the list of untracked files. Why is that?
If you've already checked in .gitignore and you want to ignore modifications to it, check out this answer:
I think that there are situations where ignoring the .gitignore is very useful. For instance, when you have multiple teams or a large team working on the same codebase. In that case, you need to have certain conventions, one of those convention is regarding what is ignored at the git repo. It is usually about ignoring files and directories created by IDE or OS, some generated logs, etc.
However, there is a force which is tending to introduce non-conventional changes to
.gitignore
file. The.gitignore
file can be further changed by irresponsible person, by mistake, by a tool that is used, or in some other case.To have a counter force to this, we can do as followed:
.gitignore
file is "sealed" in this way.The "sealed"
.gitignore
file can be changed, just locally, without propagating that changers to other members of team(s). However, if a change is widely agreed throughout the whole team(s) than it is possible to "unseal" it, change it and than "seal" it again. That can't be done by mistake, only intentionally.Sadly, you cannot be 100% protected from the stupidity, but this way you have done everything you can to prevent stupid things to happen.
If you have relatively small team with very good professionals, than this wouldn't be important, but even those guys would appreciate to have one thing less to worry about.
Using
.git/info/exclude
is cool when you cannot do anything about infrastructure settings, just covering your own a** not to make a mistake.From a standing point of what is right and what is wrong I am voting for having .gitignore entry inside
.gitignore
file, giving everybody the freedom to do locally whatever they want, but not invading others.I found that the best place to set up an ignore to the pesky
.DS_Store
files is in the.git/info/exclude
file.IntelliJ seems to do this automatically when you set up a git repository in it.
.gitignore
is about ignoring other files. git is about files so this is about ignoring files. However as git works off files this file needs to be there as the mechanism to list the other file names.If it were called
.the_list_of_ignored_files
it might be a little more obvious.An analogy is a list of to-do items that you do NOT want to do. Unless you list them somewhere is some sort of 'to-do' list you won't know about them.
You could actually put a line ".gitignore" into your ".gitignore" file. This would cause the ".gitignore" file to be ignored by git. I do not actually think this is a good idea. I think the ignore file should be version controlled and tracked. I'm just putting this out there for completeness.
Of course the .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 .gitignore!
So, the answer is simple: just add the line:
to your .gitignore file!
And, contrary to August's response, I should say that it's not that the .gitignore file should be in your repository. It just happens that it can be, which is often convenient. And it's probably true that this is the reason .gitignore was created as an alternative to .git/info/exclude, which doesn't have the option to be tracked by the repository. At any rate, how you use your .gitignore file is totally up to you.
For reference, check out the gitignore(5) manpage on kernel.org.