This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

📣 Join the live AMA session with Adam Silverstein on open source and WordPress core! Register Now →

Magento 2 Gitignore (Purpose, Pattern & File)

Updated on March 9, 2022

3 Min Read
Magento 2 Gitignore

As a developer, the task of adding thousands of files or directories falls to you when the scope of your Magento project grows. That’s where the Git repository comes in. Git helps developers track all happenings within the modules and files that contain thousands of lines of code (LOC), so all the developers are on the same page. 

But some minor changes might be overlooked when you’re going through these activities. How do you use Git to get around this?

For that, we use Magento 2 gitignore. This is a .gitignore file with the Magento Open Source project repository.

What is Git? 

Before I delve into an explanation of Magento 2 gitignore, Let’s quickly talk about Git. It’s an open-source control system that was built to help developers on all kinds of projects, from a static website to a gigantic complex ERP solution. It is an easy-to-learn, use, and master tool that helps every dev-team in their day-to-day operations. 

Apart from that, if you are a Cloudways user, you can deploy code to your Magento application from your git repositories. Ensure that your git repository supports Git over SSH to get this task done.

Book a Personalized Cloudways Product Demo With One of Our Expert

The Purpose of Magento 2 Gitignore

Magento gitignore ensures that certain files remain untracked by Git.

If you want to stop tracking a file that was or is currently being tracked, use the command below: 

git rm --cached

Also, the files that have already been tracked by Git are not affected.

Magento 2 Gitignore Pattern

Here are some helpful ways to understand the Magento 2 gitignore pattern:

  • A blank line with no match files serves as a separator for readability. 
  • A line starting with # serves or represents a comment. Place a backslash (\) in front of the first # for the patterns that begin with a hash.
  • By default, trailing spaces are ignored. It will be useless until you won’t use them with a backslash (\).
  • An optional prefix “!” negates the pattern. It helps add any matching file that was excluded by a previous pattern.*

*Please note, it is not possible to reinclude a file if a parent directory of that file is excluded or deleted. Git doesn’t mention excluded directories for performance issues. If you want to use it, here’s an example, “\!footer!.txt”.

  • The slash (/) is used as the directory separator. Separators occur at the beginning, middle, or end of the .gitignore search pattern.
  • If you find the separator at the beginning or middle, the pattern is relative to the directory level.
  • The separator at the end of the pattern only matches the directories.

For example, the pattern doc/chroz/ matches doc/chroz directory, but not a/doc/chroz directory. However, chroz/ matches chroz and a/chroz which is a directory and relative from the .gitignore file.

  • An asterisk (*) matches or accepts anything except a slash (/). 
  • The character (?) matches any one character except (/). 
  • The range notation, e.g. [a-zA-Z], can be used to match one of the characters in a range. See fnmatch(3).
  • The two consecutive asterisks (**) in patterns matched against full pathname.

For example, “**/ashcode” matches file or directory “ashcode” anywhere, the same as pattern “ashcode”.

  • A trailing (/**”) helps match all files inside the directory.
  • A slash (/) followed by two consecutive asterisks (**) then a slash (/) matches zero or more directories. For example, (/**/) – (a/**/b) matches (a/b), (a/x/b), etc. 

The Magento 2 Gitignore File 

Simply put, a Magento gitignore file contains the patterns of files used to untrack useless directories. Besides, gitignore for Magento is also published with the source on Github.

/.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

 

Final Words

That’s all about Magento 2 gitignore! You can also meet Magento 2.4 server requirements with Cloudways and experience better store performance.

 If you have any queries about the Magento gitignore file, share them in the comment section.

 

Share your opinion in the comment section. COMMENT NOW

Share This Article

Abdur Rahman

Abdur Rahman is the Magento whizz at Cloudways. He is growth ambitious, and aims to learn & share information about Ecommerce & Magento Development through practice and experimentation. He loves to travel and explore new ideas whenever he finds time. Get in touch with him at [email protected]

×

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour

CYBER WEEK SAVINGS

  • 0

    Days

  • 0

    Hours

  • 0

    Mints

  • 0

    Sec

GET OFFER

For 4 Months &
40 Free Migrations

For 4 Months &
40 Free Migrations

Upgrade Now