I was recently pushing some code for WordPress to a repository on BitBucket, and had an issue with total repo size. There is a 2GB limit for repositories on BitBucket, and unfortunately the site I was attempting to upload had a lot of images in the wp-content/uploads directory. In the process of fixing the issue, I learned a bit about .gitignore files. Not only is a .gitignore file great for restricting images from your repo (theoretically images don’t need to be version controlled), but it’s also good for restricting the upload of sensitive files such as those with DB connection credentials.
Creating a gitignore file is easy!
Navigate to the root of your Git repository.
Initialize and edit the file .gitignore with your favorite Linux text editor.
I prefer Nano.
# touch .gitignore # nano .gitignore
Find a .gitignore template to start with.
Head on over to the gitignore repo on GitHub. This repo has a collection of community maintained gitignore templates for creating ignore files related to some of the most common apps, languages, and frameworks (i.e. zend, perl, ruby, WordPress, etc).
Type whatever you’d like into your .gitignore file.
I added the following to mine:
*.log .htaccess sitemap.xml sitemap.xml.gz wp-content/advanced-cache.php wp-content/backup-db/ wp-content/backups/ wp-content/blogs.dir/ wp-content/cache/ wp-content/upgrade/ wp-content/uploads/ wp-content/wp-cache-config.php wp-admin/ wp-includes/ wp-*.php !wp-config.php index.php
Basically, this file says ignore the .htaccess and sitemap files, some heavy image directories within the wp-content folder, and most of the core files in the root except for wp-config.php.
Save the .gitignore file, commit it to your repo, and away you go. For any future commits, no new files restricted within your .gitignore file will be added.
When git ignores your… .gitignore?