How to Git-Ignore Symlinks on a Magento Module installed by composer

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 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;
done

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

Tags:

Git

Composer