Magento 2 Gitignore (Purpose, Pattern & File)

Magento 2 Gitignore (Purpose, Pattern & File)

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

Optimizing Magento Speed

Optimize Magento Speed Like a Pro

Subscribe now and get a free ebook to your inbox.

Thank You

Your Ebook is on it’s Way to Your Inbox.

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 gitignore for Magento! 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.

 

Boost Your Magento Store Performance by 5x Times & Maximize Your Sales

Our fastest Magento hosting can help you in growing your business revenue by 500%

Magento 2 Gitignore (Purpose, Pattern & File) 1

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!

Do you like what you read?

Thank you for your feedback!

Keep reading the article at The Official Cloudways Blog. The article was originally written by Abdur Rahman on 2020-11-28 09:36:51.

The article was hand-picked and curated for you by the Editorial Team of WP Archives.

Disclosure: Some of the links in this post are "affiliate links." This means if you click on the link and purchase the product, We may receive an affiliate commission.

Leave a Comment

Your email address will not be published. Required fields are marked *

Show Your ❤️ Love! Like Us
Scroll to Top