I install modules using composer.phar.

This creates symlinks files in publichtml/app/code/community (for example) with a target to vendor/themodule....

In my .gitignore I excluded the vendor directory - but the links would of course still end up in the git.

Is there an easy way to automically exclude those links? (other than adding everything manually to the .gitignore)

I have to say that I have some require-dev modules which should not end up on the final server - so having those links there would be at least not so nice.

  • 1
    Would this apply to modman, too? – philwinkle Jun 11 '13 at 16:18
  • With modman you generally would use git submodules for each extension and simply add the symlinks to the repository. No need to exclude them there, on the contrary, it wouldn't make sense in a modman deploy scenario mostly. – Vinai Jun 11 '13 at 17:01
  • 1
    @philwinkle I recently started tracking the Magento root in a separate repo for security reasons (e.g. easily detect modified files), to track changes to index.php and Mage.php, and for easier Magento upgrades so definitely relevant for modman as well, IMO. – ColinM Sep 30 '14 at 21:00

The best I came up with was running this after an composer install/update

$ find * -type l -not -exec grep -q "^{}$" .gitignore \; -print >> .gitignore

The command should be run in the git root directory. It adds all symlinks to the .gitignore file that aren't in there already.

  • this generates path's like ./foo/bar .. I think we have to remove the first . - did it work for you like that? – Alex Jun 13 '13 at 17:03
  • Works fine for me with the leading ., yes. Else sed to the rescue: find . -type l -not -exec grep -q "{}" .gitignore \; -print | sed 's/^\.\///' – Vinai Jun 13 '13 at 17:32
  • Actually, that breaks the grep... well, maybe there is a good way to clean the path up anyway... – Vinai Jun 13 '13 at 17:53
  • 1
    Simple solution: find * .... Will update my answer. – Vinai Jun 13 '13 at 18:04

This method only adds untracked symlinks so can be repeated without adding duplicate entries, symlinks that are in submodules or are otherwise already ignored, or intentionally tracked symlinks.

for f in $(git status --porcelain | grep '^??' | sed 's/^?? //'); do
    test -L "$f" && echo $f >> .gitignore;
    test -d "$f" && echo $f\* >> .gitignore;

Nowadays there is an option for this in the composer installer. Just set extra.auto-add-files-to-gitignore https://github.com/magento-hackathon/magento-composer-installer/blob/master/README.md#auto-add-files-to-gitignore


The combined solution of @ColinM and @Vinai that works for me

for f in $(git status --porcelain | grep '^??' | sed 's/^?? //'); do
    if test -L "$f"
        test -L "$f" && echo $f >> .gitignore;
    elif test -d "$f"
        find ${f%/} -type l -not -exec grep -q "^{}$" .gitignore \; -print >> .gitignore
  • Did you notice that recent composer installers auto exclude the symlinks? – Alex Feb 1 '16 at 16:15
  • Sure, but some of my projects is not under composer control. And solutions provided here are not only for composer projects but for ignoring symlinks altogether. Hope it will help somebody – martin_mageworx Feb 2 '16 at 6:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.