Where does the .gitignore file belong?

Solution 1:

Put .gitignore in the working directory. It doesn't work if you put it in the .git (repository) directory.

$ ls -1d .git*
.git
.gitignore

Solution 2:

As the other answers stated, you can place .gitignore within any directory in a Git repository. However, if you need to have a private version of .gitignore, you can add the rules to .git/info/exclude file.

Solution 3:

You can place .gitignore in any directory in git.

It's commonly used as a placeholder file in folders, since folders aren't usually tracked by git.

Solution 4:

When in doubt just place it in the root of your repository. See https://help.github.com/articles/ignoring-files/ for more information.