Best practices for using Git with Magento?

acorncom picture acorncom · Dec 30, 2010 · Viewed 10.3k times · Source

I'm working at figuring out how to best work within my own repo for custom code while integrating with a vendor's library (in this case Magento). In my case, I will not need to push up patches to the vendor (although that would be a great side benefit).

I've looked into git submodule and git subtree. I don't think git submodule will work for what I need. Magento has the following type of tree structure:

/app
  /code
     /community *
     /core
     /local *
  /design
     /adminhtml
     /frontend
        /base
        /yourtheme *
/lib
  /Zend
  /Varien
  /yourlib *
/js
  /yourjs *
  /varien
  /mage

Using git submodule seems to work best in separate folders (e.g. / is your app and /vendor/magento is the submodule). However, with this degree of intertwining, a submodule doesn't seem like a good solution. Am I wrong about this?

That leaves me with git subtree. But with git subtree, the same core assumption (that the vendor branch is, as implied by the name, a subtree) doesn't hold true. Magento isn't a subtree, but the core library that my project fits within. Is that correct?

If those two methods of git don't work, are there other ones I should know about that would do what I'm trying to accomplish?

The final option I'm reluctant to pursue is having a repo that I then just apply over the latest vendor changes (pulled in from a tarball). I'm reluctant to pursue this as I feel that having the vendor's log information (pulled from https://github.com/magentomirror/magento-mirror) would be greatly helpful in sorting through new updates and figuring out what changes have affected me.

Answer

wik picture wik · Mar 10, 2011

Non of those methods you mention really worked for me...

Currently I'm using pear to install and manage upgrades of core and community modules, and committing entire magento structure into the git repository with the following .gitignore file:

# Dynamic data that doesn't need to be in the repo
/var/*
/media/*
/downloader/pearlib/cache/*
/downloader/pearlib/download/*
/app/etc/use_cache.ser
local.xml

and using the following shell command to keep empty directories:

for i in $(find . -type d -regex ``./[^.].*'' -empty); do touch $i"/.gitignore"; done;

Another idea I thought about it's to give a try a vendor branching model, but I'm afraid it will add extra headache especially in case of some large dependency trees, i.e. for the real efficiency it's must be integrated on the pear level, i.e. every downloaded module must be branched automatically, so, for now it's seems good to use with paid extensions only.

I was tried to fire up the subject on magento forum, but also didn't got any replies: http://www.magentocommerce.com/boards/viewthread/78976/

Update:

Magento Composer Installer - worth looking.

Composer becoming standard dependency management tool for PHP, so, you'll get much more advantages utilizing it with in your project.

You won't need commit nor branch extensions, themes, libs into your project tree, but always have proper versions and dependencies.

Thanks.