.gitignore for Magento 2
52 ignore rules for Magento 2, ready to copy into your repository.
Magento version 2
The complete .gitignore for Magento 2
# Generated by LFGitignore - https://lfgitignore.com
# Created: 2026-08-05 01:33:50 UTC
# Technologies: Magento 2
### Magento 2 ###
/sitemap
/pub/sitemap
/pub/sitemap.xml
/app/config_sandbox
/app/etc/config.php
/app/etc/env.php
/app/code/Magento/TestModule*
/lib/internal/flex/uploader/.actionScriptProperties
/sitemap.xml
/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
/.grunt
/.php_cs.cache
/grunt-config.json
/dev/tools/grunt/configs/local-themes.js
/pub/media/*.*
!/pub/media/.htaccess
/pub/media/attribute/*
!/pub/media/attribute/.htaccess
/pub/media/analytics/*
/var/*
!/var/.htaccess
/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/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/media/captcha/.htaccess
/pub/static/*
!/pub/static/.htaccess
/vendor/*
!/vendor/.htaccess
/generated/*
!/generated/.htaccess
What these Magento 2 rules actually ignore
Every pattern below, and why it belongs in your .gitignore.
General
| Pattern | What it ignores |
|---|---|
/sitemap |
General |
/pub/sitemap |
General |
/pub/sitemap.xml |
General |
/app/config_sandbox |
General |
/app/etc/config.php |
General |
/app/etc/env.php |
General |
/app/code/Magento/TestModule* |
General |
/lib/internal/flex/uploader/.actionScriptProperties |
General |
/sitemap.xml |
ignore sitemap.xml |
/lib/internal/flex/uploader/.flexProperties |
General |
/lib/internal/flex/uploader/.project |
General |
/lib/internal/flex/uploader/.settings |
General |
/lib/internal/flex/varien/.actionScriptProperties |
General |
/lib/internal/flex/varien/.flexLibProperties |
General |
/lib/internal/flex/varien/.project |
General |
/lib/internal/flex/varien/.settings |
General |
/.grunt |
General |
/.php_cs.cache |
General |
/grunt-config.json |
General |
/dev/tools/grunt/configs/local-themes.js |
General |
/pub/media/*.* |
General |
!/pub/media/.htaccess |
General |
/pub/media/attribute/* |
General |
!/pub/media/attribute/.htaccess |
General |
/pub/media/analytics/* |
General |
/var/* |
General |
!/var/.htaccess |
General |
/pub/media/catalog/* |
General |
!/pub/media/catalog/.htaccess |
General |
/pub/media/customer/* |
General |
!/pub/media/customer/.htaccess |
General |
/pub/media/downloadable/* |
General |
!/pub/media/downloadable/.htaccess |
General |
/pub/media/favicon/* |
General |
/pub/media/import/* |
General |
!/pub/media/import/.htaccess |
General |
/pub/media/logo/* |
General |
/pub/media/theme/* |
General |
/pub/media/theme_customization/* |
General |
!/pub/media/theme_customization/.htaccess |
General |
/pub/media/wysiwyg/* |
General |
!/pub/media/wysiwyg/.htaccess |
General |
/pub/media/tmp/* |
General |
!/pub/media/tmp/.htaccess |
General |
/pub/media/captcha/* |
General |
!/pub/media/captcha/.htaccess |
General |
/pub/static/* |
General |
!/pub/static/.htaccess |
General |
/vendor/* |
General |
!/vendor/.htaccess |
General |
/generated/* |
General |
!/generated/.htaccess |
General |
How to use this .gitignore for Magento 2
- Copy the Magento 2 rules above, or download the file directly.
- Create a file named .gitignore at the root of your Git repository and paste the rules into it.
- If some of those files are already tracked, run git rm -r --cached . then commit again — Git only applies ignore rules to untracked files.
- Commit the .gitignore so everyone on the team shares the same rules.