6

I would like to know whether it is possible to have named .gitignore files in a repository, such as:

Composer.gitignore
Node.gitignore

Both of the above examples are shown available in GitHub's gitignore template repository (perhaps this might be a bit misleading).

I have tried adding Composer.gitignore to my repository and it seems like the file is not read (I'm using SourceTree).

EDIT:

Adding relevant information added by Boldewyn that does not directly answer the question:

The page's README says:

A Collection of .gitignore templates and that's what it is: Only templates. If you want to use one, pick it, drop it in your repository and rename it to .gitignore.

git recognizes only two places for listing ignored files: .gitignore files in a folder/subfolder and the file .git/info/ignore. See git help gitignore for in-depth information.

Community
  • 1
  • 1
jolian
  • 73
  • 1
  • 6

2 Answers2

7

The only way you could make a file not name .gitignore as a .gitignore file is:

  • reference it directly

    git config --global core.excludesfile ~/myfile.gitignore
    
  • generate it through a smudge script from a content filter driver.
    That second option is a bit convoluted, but would process all versionned <file>.gitignore and generate the final .gitignore.

Other than those two options, the .gitignore man page doesn't allow any other naming convention.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
5

The page's README says:

A Collection of .gitignore templates

and that's what it is: Only templates. If you want to use one, pick it, drop it in your repository and rename it to .gitignore.

git recognizes only two places for listing ignored files: .gitignore files in a folder/subfolder and the file .git/info/ignore. See git help gitignore for in-depth information.

Boldewyn
  • 81,211
  • 44
  • 156
  • 212
  • I will copy your answer as an edit to my Question, as even though it does not directly answer my question it adds very important information. – jolian Mar 16 '15 at 12:13