If you chose Git as your favorite version control system and use it in your Magento project, you probably want to exclude some files from your Magento installation when pushing it to a remote repository – for example files that contain passwords or ones that could compromise safety or of your project in any other way. Such files should be only kept locally – imagine what would happen if you made an automatic deployment from Git repository to your client’s server, overwriting his local.xml file with your development one. One client less to worry about.
Here is a list of files that should be put in the
.gitignore file in the main directory of your project:
app/etc/local.xml contains all the settings for your Magento installation, including database username and password. Media-related entries are for temporary files and for auto-generated thumbnails and small images that Magento generates from bigger product images provided. The
errors/local.xml, if it’s there, manages error reporting – and by default print errors on the screen, so if there are any errors on the website, users see them in their browsers. Bad for business, believe me. Next directory,
var stores auto-generated information like sessions states, cached files or error reports. You don’t want it in your repository, because every fresh website instance should have its sessions and cache cleaned out to ensure that the system really takes your files you modify into consideration when displaying things. The last directory there, the
downloader directory, stores information about extensions downloaded from Magento Connect. It’s irrelevant for development purposes, because once they’re installed, they are in the rest of directories (e.g.
skin/frontend/base/default – depending on extensions themselves) and you don’t need the info that they were installed via connect or how their ready-to-install packages look like.
The last declaration in the
.gitignore also require some explanation. It’s an exlusion made for
.htaccess files inside directories other than root. These files exist in various of places, including your ignored
downloader directories. They shouldn’t be ignored, because they contain some important information, like denying access to session-related files. That’s why, though we ignore entire
downloader directories, there is this one file in each of them that we want to keep.
It’s also worth mentioning that because we don’t ignore
.htaccess files in
downloader, those directories will still show up when you use
git status or any other command that shows files and directories. But although they’re there, Git sees only
.htaccess files inside – so don’t worry about using
git add var/. command, or anything like that. You won’t add any unnecessary files this way.
There may be situations when you don’t want to ignore only Magento-related files. There may be other files, like project files/directories created by IDEs that you, or other developers working on the same project work or worked on. You may also see projects containing .httpasswd files – they also should be ignored for security reasons. Here is a
.gitignore file ignoring
.htpasswd file and files created by some major PHP IDEs like NetBeans (
nbproject dir), PhpStorm (
.idea dir), Eclipse (
.project file) and Aptana Studio (based on Eclipse, so the file is the same):