Fine Tuned Source Code Management with a Custom Git Ignore File for Drupal
November 05, 2014

Introduction

Source code management, also known as code version control, source control, and revision control, is essential to say the least. For programming, it was and it always will be even more than essential. For other types of documents, it is becoming more and more essential and we are seeing business managers and graphic designers alike using version control nowadays.

To learn more, visit Wikipedia's entry about revision control, and if you're a developer, I suggest you stop anything you're doing now, installing Git on your machine, and taking it from there. You also definitely have to familiarize yourself with GitHub.

Default Source Code Management in Drupal

As of this writing, Drupal 7.32 ships with the following .gitignore file.

# Ignore configuration files that may contain sensitive information.
sites/*/settings*.php

# Ignore paths that contain user-generated content.
sites/*/files
sites/*/private

Simple, effective, and secure.

For the beginners, a .gitignore file tells the Git SCM which files should "not" go under source version control. It's a security requirement to ignore sensitive configuration files containing passwords and other credentials. It's also good practice to ignore user generated content as those are usually not code related.

Quick Note on Version Control vs Backup

Since user generated content is not under version control, that doesn't mean you shouldn't be backing it up. However, backup and source control are different concepts and should be handled accordingly. In a nutshell, your code should be backed up and also source controlled, your configuration files should be backed up, your source control generated files should be backed up, and user generated content should be backed up as well.

Custom Source Code Management in Drupal

The default version control management in Drupal, based on the .gitignore file presented above, will add all of Drupal's files under version control. If you want to only add the custom themes and custom modules you write for Drupal under version control, and ignore everything else, you're in luck, as we have done the mundane work for you with our custom .gitignore file below.

Note that we don't always recommend this approach as it might be useful to also source control Drupal's standard files, even if you're not responsible for them. However, in certain cases, this custom .gitignore file might be needed. In addition, it's always good to share and open source our resources as anyone might learn new Git tips and tricks here and apply them in a different context.

As usual, read the comments in the code below for more details.

Happy coding.

 

################################################################################
# Git ignore file for Drupal 7 based projects. 
# This will only include custom themes and modules under source control.
# Developed by Mario Awad of SOFTKUBE s.a.r.l. - http://softkube.com/
################################################################################

# Ignore all root files excluding .gitignore (this file) and .htaccess cause you
# never know when they will be needed and if a Drupal update will overwrite them
/*.php
/*.txt
/*.ico
/*.config

# Ignore the Netbeans files directory and also all default Drupal directories
# excluding the sites directory which we'll carefully ignore below
/nbproject/
/includes/
/misc/
/modules/
/profiles/
/scripts/
/themes/

# Carefully ignore the sites directory while making sure the only files and
# directories that will be kept are under the themes directory we always use
/sites/*.*
/sites/default/
/sites/all/*.*
/sites/all/modules/
/sites/all/libraries/
/sites/all/themes/*.*

# Unignore the only module we need to track. SK.
# This works by negating the parent directory as above it's ignored, then apply.
# We kept it this way so that we can remove this whole section if needed.
# Reference: http://stackoverflow.com/questions/5533050
!/sites/all/modules/
/sites/all/modules/*
!/sites/all/modules/sk/

Drupal Development Open Source

Share this post


Written by
Mario Awad

Founder of SOFTKUBE, lead developer, and getting things done addict. Passionate about open source, user interface design, business development, and the tech world.

More about Mario Awad


About
SOFTKUBE

A small team of experts developing simple, usable, and high-quality web solutions. We blog about business, entrepreneurship, web development, and technology.

More about us


Recent Posts

Gaining Access to a Legacy Google Apps Account When Phone Verification Fails

Custom Theme Migration from Drupal 9 to Drupal 10

How to Change the Most Recent Git Commit Message

How to Make Google Chrome Forget a Permanent HTTP 301 Redirect

View all posts


All Posts Categories

Business Cheat Sheets CLI Design Development Downloads Drupal Email Google Apps HID Keyboards Multilingualism Open Source Philosophy PHP Pointing Devices Productivity Quotes Science Security SEO Technology Thoughts Windows Zend Framework