.gitignore: Difference between revisions
(2 intermediate revisions by the same user not shown) | |||
Line 26: | Line 26: | ||
=Pattern Format= | =Pattern Format= | ||
==Ignoring Directories== | |||
To ignore a directory, and recursively their content, specify then name of the directory (without any trailing slash). Example: | |||
<syntaxhighlight lang='bash'> | |||
.idea | |||
</syntaxhighlight> | |||
This wil ignore the <code>.idea</code> directory from the same directory as the <code>.gitignore</code> file, and recursively, the <code>.idea</code> directory content. | |||
=Reference .gitignore= | =Reference .gitignore= | ||
Line 43: | Line 49: | ||
=Commands= | =Commands= | ||
* [[Git check-ingore|git check-ignore]] | * [[Git check-ingore|git check-ignore]] | ||
* [[Git add|git add]] |
Latest revision as of 05:10, 11 January 2022
External
Internal
Overview
.gitingore
specifies files to exclude from tracking.
Each line in the file specifies a path pattern, and when deciding to ignore or not a path, Git flattens the specifications from a set of files, while enforcing this precedence, listed here from highest to lowest:
- Pattern specified on command line
- Patterns read from a
.gitignore
file in the same directory as the path. - Patterns read from
.gitignore
files from parent directories. The patterns specified in.gitignore
closer to the path in the hierarchy take precedence over those specified in more distant.gitignore
files, along the directory hierarchy. - Patterns read from
$GIT_DIR/info/exclude
. - Patterns read from the file specified by the configuration variable
core.excludeFiles
.
Specify the files that all developers should ignore into .gitignore file(s) checked into the repository itself. Patterns that are specific to a particular repository but which do not need to be shared with other related repositories (auxiliary files that live inside the repository but are specific to one user's workflow) should go into $GIT_DIR/info/exclude
. Patterns which a user wants Git to ignore in all situations (backup or temporary files generated by the user’s editor of choice) generally go into a file specified by core.excludesFile
in the user’s ~/.gitconfig
. Its default value is $XDG_CONFIG_HOME/git/ignore
. If $XDG_CONFIG_HOME
is either not set or empty, $HOME/.config/git/ignore
is used instead.
Behavior in Presence of Currently Tracked Files
Files that are already tracked are not affected if a pattern that matches is specified in .gitignore
after they Git started to track them. To stop tracking a file that is currently tracked, use git rm --cached
.
Pattern Format
Ignoring Directories
To ignore a directory, and recursively their content, specify then name of the directory (without any trailing slash). Example:
.idea
This wil ignore the .idea
directory from the same directory as the .gitignore
file, and recursively, the .idea
directory content.
Reference .gitignore
To download:
Use Cases
Negate an Exclusion Pattern Declared by Upper .gitignore Files
!