Most of the time developer will add all Magento source files inside the git version control. It is much easier that way to track any change or even deploy the files on server by executing git pull.

But sometimes it is completely unnecessary to track all files and developer would like to track only few specified files and folders under web root, for example when developing Magento extension for Magento Connect.

There are already number of .gitignore pre defined files online and also we can find Magento specific ones, but when I searched, I didn’t find the one that I really need:

I don’t want .gitignore file that will ignore some files in my web root, but I rather want to have .gitignore file that will ignore everything except files I specify.

Lucky for me, there is an option to NOT ignore inside .gitignore file using ! character.

For example we can write in our .gitignore file:

#.gitignore / app /* # This means that app folder and all subfolders and files will be ignored !/app/code # This means that /app/code will NOT be ignored (will be excluded from ignore path)

Next question is: Why would I even need some .gitignore generator for few files and folders I want to EXCLUDE from .gitignore? It is much simpler to write theose lines manually, for example:

#gitignore / app /* #ignore app folder and everything under it !/app/code/community/inchoo #exclude this folder from ignore (I want to add only that under git)

Unfortunatelly, above example will NOT work! For the above case,the proper code will look like this:

# .gitignore /* # ignore everything !/app # NOT ignore app /app/* # ignore app/everything !/app/code # NOT ignore app/code /app/code/* ignore app/code/everything !/app/code/community # NOT ignore app/code/community /app/code/community/* # ignore app/code/community/everything !/app/code/community/inchoo # NOT ignore /app/code/community/inchoo !.gitignore # NOT ignore .gitignore file

Since this is too much code to write by myself everytime, I decided to create small (NOT).gitignore generator and to share it with you!

Usage is pretty simple:

Insert path for each file/folder that you want to track with git one per line. Files and folders that are not on this list will be ignored.

Path must be relative to main .git folder.

For example if we have Magento installation and want to track with git our extension files only, we should enter something like this in generator field:

app/code/community/Inchoo

app/design/frontend/base/default/layout/inchoo

app/design/frontend/base/default/template/inchoo

app/skin/inchoo

Next just press GENERATE link and copy/paste this text in own .gitignore file.

Please enter paths for needed files:





GENERATE .gitignore >>

Generated result; copy and paste this to your .gitignore:



I hope that you will find this little tool useful in own projects.

Cheeers 🙂