(Not only) Magento .gitignore generator

(Not only) Magento .gitignore generator © SteveFE@sxc.hu

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.




GENERATE .gitignore >>


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

Cheeers :-)

You made it all the way down here so you must have enjoyed this post! You may also like:

How to generate SSH keys for Git authorization Hrvoje Ivancic
, | 21

How to generate SSH keys for Git authorization

Adding custom credit card type to your payment method in Magento Toni Peric
Toni Peric, | 2

Adding custom credit card type to your payment method in Magento

Magento with xDebug, web services API and testUnit Darko Goles
Darko Goles, | 5

Magento with xDebug, web services API and testUnit

11 comments

  1. Git allows recursive file/folder ignore/exclude commands. I use a variation of the following for my projects (changed to reflect the example in the article):


    app/**
    !app/**/
    !app/code/community/inchoo/**

    `app/**` “ignore every folder and file under app, recursively”.
    `!app/**/` “exclude every folder under app, recursively”; git is intelligent enough that empty folders do not get added.
    `!app/code/community/inchoo/**` “exclude every folder and file in this folder, recursively”.

    The net effect is that the folder “app/code/community/inchoo/” and all its files are added to the git repo.

    Happy coding 😉

  2. I personally use modman like @Anton suggested. However this makes for a great alternative when developing extensions for Magento Connect. The generator is great, good work!

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.