How to Create a Magento 2 Gitignore File

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

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:

  • /pub/media/.
  • /sitemap
  • /node_modules
  • /package.json
  • /pub/static/*

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.



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.

Nikita S.
Nikita S.
Lead Technical Writer

As a lead technical writer, Nikita S. is experienced in crafting well-researched articles that simplify complex information and promote technical communication. She has expertise in cloud computing and holds a specialization in SEO and digital marketing.

Get the fastest Magento Hosting! Get Started