Add .gitignore to gitignore

A .gitignore can ignore itself if it's never been checked in:

mhaase@ubuntu:~$ git --version
git version 1.7.9.5
mhaase@ubuntu:~$ git init temp
Initialized empty Git repository in /home/mhaase/temp/.git/
mhaase@ubuntu:~$ cd temp
mhaase@ubuntu:~/temp$ touch .gitignore foo bar baz bat
mhaase@ubuntu:~/temp$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       .gitignore
#       bar
#       bat
#       baz
#       foo
mhaase@ubuntu:~/temp$ echo "foo" >> .gitignore
mhaase@ubuntu:~/temp$ echo ".gitignore" >> .gitignore
mhaase@ubuntu:~/temp$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       bar
#       bat
#       baz
nothing added to commit but untracked files present (use "git add" to track)

If you check in .gitignore (before you tell it to ignore itself), then it will always show up in git status, even if you later modify it to ignore itself.


The .gitignore file's purpose is to prevent everyone who collaborates on a project from accidentally commiting some common files in a project, such as generated cache files. Therefore you should not ignore .gitignore, since it's supposed to be included in the repository.

If you want to ignore files in just one repository but want to avoid committing the ignore list (for example for personal files) you can add them to .git/info/exclude in that repository.

If you want to ignore certain files on every repository on your machine you can create the file ~/.gitignore_global and then run

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

Tags:

Git

Gitignore