Before shedding light on Magento 2 gitignore files, we’d like to draw your attention to Git itself. Being a free and open source software, this version control system is developed to help you with all possible projects from basic small to complicated large ventures. Git is easy to learn and master, powerful, and full-featured solution, which outperforms such SCM tools as Subversion, Perforce, or CVS. Moreover, you can easily learn it right in your browser via
Table of contents
Magento 2 gitignore purpose
The purpose of every gitignore file is to specify intentionally untracked files that should be ignored by Git. Please note that Git can already track some files, so they won’t be affected. To stop tracking a currently tracked file, use the following command:
git rm --cached
Magento 2 gitignore structure
All gitignore files consist of a various number of lines, each of which specifies a pattern. Git checks these patterns to decide what path to ignore. The following order is utilized: a precedence from the highest to lowest levels. In case of a single precedence level, Git relies on the last matching pattern to produce the outcome.
Git ls-files, git read-tree, as well as other underlying Git plumbing tools, read gitignore patterns specified by CLI options. Alternatively, they can be specified from files specified by such options. As for git status, git add, and other higher-level Git tools, they rely on patterns from sources specified
Magento 2 gitignore pattern format
- A blank line can be utilized as a separator which increase readability, since it matches no files.
- Start a line with # to leave a comment. If you have a pattern which begins from #, place \ before the first #.
- Since trailing spaces are ignored by default, you should use \ to make them valid.
- ! is an optional prefix that negates the pattern, but if you have a matching file which is excluded by a previous pattern, it will become included again. Note that it is impossible to include a file one more time if its parent directory is excluded. Directories are not excluded by Git for performance reasons. If you have a pattern that starts with !, place \ before the first !.
- If a slash is used on the end of a pattern, it is removed for the following description purpose.
- As for patterns without a slash, Git treats them as a shell glob patterns. It checks for a match against the pathname corresponding to the .gitignore file location.
For further information on gitignore pattern format, check the official documentation:
Magento 2 gitignore file
You can find the most reliable gitignore file for Magento 2 here: