Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.gitignore shows up when I run git status

Tags:

git

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

Contents of .gitignore:

images/builder/
like image 770
ram1 Avatar asked Oct 21 '11 04:10

ram1


People also ask

Why is Gitignore showing up in untracked files?

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 .

Should the .gitignore file be tracked?

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.

Does git track Gitignore?

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


3 Answers

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.

like image 178
snogglethorpe Avatar answered Oct 02 '22 12:10

snogglethorpe


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.

like image 38
therin Avatar answered Oct 02 '22 13:10

therin


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

like image 44
Michael Durrant Avatar answered Oct 02 '22 13:10

Michael Durrant