Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.gitignore isn't ignoring itself [duplicate]

Tags:

git

gitignore

I added .gitignore and another directory to my .gitignore file, but when I git status, .gitignore is still showing up!

I feel like I'm missing something really obvious.

like image 523
Colleen Avatar asked Dec 20 '12 18:12

Colleen


People also ask

Why is Gitignore not ignoring itself?

gitignore file only ignores untracked files. Since you're presumably tracking your . gitignore file, you will see changes to it in the output of git status . If you want to ignore something but you don't want to check it in, add it to your global git ignore file instead of the one checked into the repository.

Why is my file not being ignored in Gitignore?

gitignore ignores only untracked files. Your files are marked as modified - meaning they were committed in the past, and git now tracks them. To ignore them, you first need to delete them, git rm them, commit and then ignore them.

Should Gitignore ignore itself?

No, . gitignore needs to be checked in so that other users ignore the same files.

Why is my .gitignore file not working?

Check the file you're ignoring Take a good look at your structure, and make sure you're trying to ignore the file that isn't already committed to your repository. If it is, remove the file from the repository and try again. This should fix the Gitignore not working issue.


2 Answers

As Carl Norum pointed out, files are not allowed to be tracked in order to be ignored. You will have to call

git rm --cached .gitignore

in order for it to actually be ignored.

But what you are trying to do is a very bad idea. The .gitignore file is supposed to be tracked, so it’s ensured that the stuff listed in there is actually ignored on all client machines. If that’s not the case, another dev might add a file to the repo that you wanted to ignore, and you will get into trouble.

Even running the command above might already cause trouble, as it will delete that file for every dev.

If for some reason you want to ignore stuff only on your machine (and you are sure that’s a good idea), you need to add that to .git/info/exclude. That file has the same function as .gitignore, but is not supposed to be shared with the other devs.

like image 86
Chronial Avatar answered Sep 28 '22 07:09

Chronial


Stop tracking the .gitignore file:

How to stop tracking and ignore changes to a file in Git?

git rm --cached .gitignore 
like image 36
Layton Everson Avatar answered Sep 28 '22 06:09

Layton Everson