.gitignore generator for Magento

Git is a distributed revision control system with an emphasis on speed, data integrity, and support for distributed, non-linear workflows. it’s important for many projects and Magento is not an exception. for many beginners or even experienced developers, a good .gitignore file is not always in their mind, this is source of many sins in the future to other developers who get in the line of the same project later.

i created a bash script and have been using it for awhile. You can generate a good .gitignore file from now on and stop worrying about git related issues in the future. you can find the script below

#! /bin/bash
# generate .gitignore
# add rules to.gitignore automatically
#author: Atheotsky
 
GIT=.gitignore
 
# find exception under a directory. $1 : directory, $2 keyword
getExceptions()
{
SUBDIRS=$(find $1 -type d -iname $2 | grep -i media | sort | awk '$0 !~ last "/" {print last} {last=$0} END {print last}')
}
 
find . -name '.svn' -depth -exec rm -rf {} \;
find . -name '*_DS*' -depth -exec rm -rf {} \;
find . -type d -empty -exec touch {}/$GIT \;
touch $GIT;
 
#default rules
echo 'app/etc/local.xml' >> $GIT;
echo '.htaccess' >> $GIT;
echo 'app/.htaccess' >> $GIT;
echo 'errors/local.xml' >> $GIT;
echo 'tasks.txt' >> $GIT;
 
#directories must have slash / to make sure git won't mistake it with file
echo '.idea/' >> $GIT;
echo '.modgit/' >> $GIT;
echo 'includes/' >> $GIT;
echo 'media/' >> $GIT;
echo 'nbproject/' >> $GIT;
echo 'var/' >> $GIT;
 
echo '.DS_Store' >> $GIT;
echo '*.swp' >> $GIT;
echo '*.swn' >> $GIT;
echo '*.swo' >> $GIT;
 
#add exceptions - invoke function with param directory and keyword
echo '#files & folders exception' >> $GIT;
 
getExceptions 'app' 'media'
for line in $SUBDIRS
do
printf "!%s\n" $line >> $GIT;
done
 
getExceptions 'skin' 'media'
for line in $SUBDIRS
do
printf "!%s\n" $line >> $GIT;
done
 
getExceptions 'js' 'media'
for line in $SUBDIRS
do
printf "!%s\n" $line >> $GIT;
done
 
#do git initialize
git init;
git add . ;
git commit -m 'Initial Import';

i added comments for each section, i hope you can get it without problem ๐Ÿ˜›

Leave a Comment