How to Create a Magento 2 Gitignore File
A Gitignore File contains patterns of intentionally untracked files.
While working on a Magento project, you deal with thousands of lines of code using Git.
Gitignore ensures you can ignore specific files, so they are not tracked.
We cover what a Gitignore file is and how to create a Magento 2 gitignore file.
What is Git?
Git is an open-source distributed version control system. It is used to track changes in any set of files.
Git allows you to collaborate during software development and work efficiently on the source code.
It helps developers on small or large projects such as static sites or complex ERP solutions.
What is Magento 2 Gitignore
Magento gitignore ensures that specific files or directories remain untracked by Git.
The following command is used to un-track the files by removing them from the index.
The file is still present but on the next Git pull, it is untracked.
git rm --cached.
The files that are already tracked by Git are not affected.
What is the Magento 2 Gitignore Pattern?
A few ways that help understand the Magento 2 gitignore pattern:
A line starting with # represents a comment. Add a backslash () in front of the first # for the patterns that begin with a hash.
A blank line with no match files is a separator for readability.
Trailing spaces are ignored by default. It is useless until you won’t add them with a backslash ().
The prefix “!” negates the gitignore pattern. It adds any previously matching file that was excluded by a previous pattern.
Slashes (/) is used as directory separators. It is placed at the starting, middle, or end of your gitignore pattern.
Two consecutive asterisks (** ) are used in gitignore patterns to match against the full pathname. For example, “**/abcd” will match the file or directory “abcd” regardless of the full pathname.
Use two consecutive asterisks (**) preceded by a slash (/) and followed by a slash (/) to match zero or more than zero directories.
Leaving trailing asterisks (/**) at the end helps match all files in the directory.
The two consecutive asterisks (**) in patterns matched against full pathname.
A trailing (/**”) helps match all files inside the parent directory.
Magento 2 Gitignore File
A Magento gitignore file contains the patterns of files used to un-track useless directories.
Gitignore for Magento is also published with the source on Github.
To see the list of all ignored files, run the command
open.gitignore on Mac or
start.gitignore on PC.
You can choose to ignore the following files:
When making changes on Magento Website, you might have to check if these files are on this list or not.
If the files are present, you have to update those files with Git Commit.
/.buildpath /.cache /.metadata /.project /.settings /.vscode atlassian* /nbproject /robots.txt /pub/robots.txt /sitemap /sitemap.xml /pub/sitemap /pub/sitemap.xml /.idea /.gitattributes /app/config_sandbox /app/etc/config.php /app/etc/env.php /app/code/Magento/TestModule* /lib/internal/flex/uploader/.actionScriptProperties /lib/internal/flex/uploader/.flexProperties /lib/internal/flex/uploader/.project /lib/internal/flex/uploader/.settings /lib/internal/flex/varien/.actionScriptProperties /lib/internal/flex/varien/.flexLibProperties /lib/internal/flex/varien/.project /lib/internal/flex/varien/.settings /node_modules /.grunt /Gruntfile.js /package.json /.php_cs /.php_cs.cache /grunt-config.json /pub/media/*.* !/pub/media/.htaccess /pub/media/attribute/* !/pub/media/attribute/.htaccess /pub/media/analytics/* /pub/media/catalog/* !/pub/media/catalog/.htaccess /pub/media/customer/* !/pub/media/customer/.htaccess /pub/media/downloadable/* !/pub/media/downloadable/.htaccess /pub/media/favicon/* /pub/media/import/* !/pub/media/import/.htaccess /pub/media/logo/* /pub/media/custom_options/* !/pub/media/custom_options/.htaccess /pub/media/theme/* /pub/media/theme_customization/* !/pub/media/theme_customization/.htaccess /pub/media/wysiwyg/* !/pub/media/wysiwyg/.htaccess /pub/media/tmp/* !/pub/media/tmp/.htaccess /pub/media/captcha/* /pub/static/* !/pub/static/.htaccess /var/* !/var/.htaccess /vendor/* !/vendor/.htaccess /generated/* !/generated/.htaccess .DS_Store
Git allows developers to track all events within the modules and files containing thousands of code lines.
It helps developers be on the same page while working on a Magento project.
Magento gitignore ensures that specified files are ignored or not tracked by Git. We have covered the steps to set up a Magento gitignore file.
To get more insights on the Magento platform, check out MGT Commerce Tutorials.