gitignore
A gitignore file specifies intentionally untracked files that Git should ignore.
note
Files already tracked by Git aren’t affected.
To stop tracking a file that’s currently tracked, use git rm --cached to remove the file from the index.
The way git decide which files to ignore
Each line in a gitignore file specifies a pattern.
Git normally checks gitignore patterns from multiple sources:
-
From the file specified by the configuration variable
core.excludesFilein the user’s~/.gitconfig.core.excludesFile:- Default value is
$XDG_CONFIG_HOME/git/ignore1. - If
$XDG_CONFIG_HOMEis either not set or empty,$HOME/.config/git/ignore(aka~/.config/git/ignore) is used instead.
- Default value is
-
From
$GIT_DIR/info/exclude. -
From a
.gitignorefile:- in the top-level
- in any sub-directory
of the git working tree.
-
From the command line for those commands that support them.
important
The source list is in order of precedence from lowest to highest.
Within one level of precedence, the last matching pattern decides the outcome.
note
The $XDG_CONFIG_HOME defines the base directory relative to which user-specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used.
For more information, see
note
The patterns (in the .gitignore file in the working tree) match relative to the location of the .gitignore file.
For other sources, the patterns match relative to the top-level of the working tree.