ram1
ram1

Reputation: 6470

.gitignore shows up when I run git status

When I run git status, .gitignore is listed under untracked files. How do I prevent it from being listed?

Contents of .gitignore:

images/builder/

Upvotes: 13

Views: 10240

Answers (4)

snogglethorpe
snogglethorpe

Reputation: 1772

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:

  1. 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.

  2. 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.

  3. 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.

Upvotes: 9

Pablo Fernandez
Pablo Fernandez

Reputation: 105258

.gitignore should be a part of your code. You sure don't want to exclude since it's the way to tell your teammates (or yourself in another pc) which files shouldn't be commited

Upvotes: 2

Michael Durrant
Michael Durrant

Reputation: 96594

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

Upvotes: 2

therin
therin

Reputation: 1468

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.

Upvotes: 17

Related Questions