Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I stop .gitignore from appearing in the list of untracked files?

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?

like image 984
Jacques René Mesrine Avatar asked Apr 20 '09 06:04

Jacques René Mesrine


People also ask

How do I ignore all untracked files?

You can use the git clean command to remove untracked files. The -fd command removes untracked directories and the git clean -fx command removes ignored and non-ignored files. You can remove untracked files using a . gitignore file.

Does .gitignore need to 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. Also see this: Should you commit .

How do I make untracked files tracked?

You have to add the untracked files of the repository by using the “git add” command and run the “git stash” command to save the untracked file and clean the current directory for working by removing the untracked file from the repository folder.


3 Answers

The .gitignore file should be in your repository, so it should indeed be added and committed in, as git status suggests. It has to be a part of the repository tree, so that changes to it can be merged and so on.

So, add it to your repository, it should not be gitignored.

If you really want you can add .gitignore to the .gitignore file if you don't want it to be committed. However, in that case it's probably better to add the ignores to .git/info/exclude, a special checkout-local file that works just like .gitignore but does not show up in "git status" since it's in the .git folder.

See also https://help.github.com/articles/ignoring-files

like image 182
August Lilleaas Avatar answered Oct 14 '22 00:10

August Lilleaas


If you want to store the list of ignored files outside of your Git tree, you can use the .git/info/exclude file. It is applied only to your checkout of the repo.

like image 289
Paweł Hajdan Avatar answered Oct 14 '22 00:10

Paweł Hajdan


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.

like image 83
1800 INFORMATION Avatar answered Oct 14 '22 02:10

1800 INFORMATION