Henrik Sommerland
Henrik Sommerland

Reputation: 595

Why doesn't git ignore .gitgnore?

Why doesn't git ignore .gitignore? Is this a bug or is this a feature? I can't see any reason why one would like to share ones .gitignore file. It feels a bit ironic to have to add .gitignore to .gitignore.

Is there any reason for this?

Upvotes: 2

Views: 967

Answers (5)

David
David

Reputation: 3055

It's a feature.

The purpose of .gitignore files is to ensure that certain files not tracked by Git remain untracked. Thus it should be committed into the repository, in order to share the ignore rules with any other users that clone the repository.

You can also create a global .gitignore file, which is a list of rules for ignoring files in every Git repositories on your computer. For example, you might create the file at ~/.gitignore_global and add some rules to it. To add this file to your global Git configuration, run the following command in your terminal:

git config --global core.excludesfile ~/.gitignore_global

For further information you can check official documentation.

Upvotes: 1

AmazingDreams
AmazingDreams

Reputation: 3204

Put the following contents in a .gitignore file and check it out yourself:

*

Git ignores the .gitignore file!

To 'fix' this you have to:

*
!.gitignore

Upvotes: 0

Milan Baran
Milan Baran

Reputation: 4232

If you look at it from different angle. There would be probably more people asking Why does git ignore .gitignore? or How to add .gitignore to my repository? and so on. It would be much more problematic to include .gitignore to repo that to exclude it with adding it explicitly to gitignore. It could looks weird in some way, but you have to get over it.

So, that's why it is not a bug it is a FEATURE!!!

Upvotes: 0

wumpz
wumpz

Reputation: 9201

This is a feature. For example in Java you want to ignore all *.class files. So every user of your repository have to ensure, that no *.class files are committed. Therefore this is a usecase where this .gitignore should be available to all users of this repository.

Upvotes: 3

Harry Dobrev
Harry Dobrev

Reputation: 7706

In short - it's a feature.

.gitignore is not meant as a local file for every developer on a project.

You need to ignore files and folders which are not meant to be committed to the repo by anyone.

Examples: build folders, vendor folders (installed via a package manager - e.g. node_modules), binary files.

Here is a nice help article from GitHub: https://help.github.com/articles/ignoring-files

You could also check out the github/gitignore repository for examples.

E.g. Symfony2 .gitignore is ignoring logs, cache, uploads, vendor libraries installed via composer and commonly used binaries like composer.phar:

# Bootstrap
app/bootstrap*

# Symfony directories
vendor/*
*/logs/*
*/cache/*
web/uploads/*
web/bundles/*

# Configuration files
app/config/parameters.ini
app/config/parameters.yml

# Composer
composer.phar

Upvotes: 10

Related Questions