Adding Git to an existing Drupal website

If you have many Drupal websites on your server, you might want to use a Git repository to ease the upgrades. There is a Drupal repository on GitHub at https://github.com/drupal/drupal.git that contains all the releases and is up-to-date with the development CVS used at Drupal.

Prerequisites:

  • If you don’t have yet a local Git repository for Drupal on your server, these are the steps to clone one in /var/git/drupal:
    mkdir /var/git
    cd /var/git
    git clone https://github.com/drupal/drupal.git
  • We’ll assume you place your Drupal website in /var/www/$SITE/drupal.

If you already have a Drupal website you might want to follow these steps to inject a Git repository to match the same setup than with what is described in the article about a new Drupal installation with Git.

Please see the prerequisites. As an example we’ll suppose your current website runs under Drupal 6.22 — of course, you should adapt the following lines to your exact configuration:

export VERSION=6
export CURRENT_RELEASE=22
export CURRENT=drupal-$VERSION.$CURRENT_RELEASE

export SITE=_name of the existing website_

The next step will clone the Drupal Git repository in /var/www/$SITE/drupal. You don’t want to erase your current installation, so move it into a temporary directory:

cd /var/www/$SITE
mv drupal drupal-temp

Install drupal by cloning the local Git repository (See the prerequisites if you don’t have a local Git repository):

git clone /var/git/drupal

Select the matching Drupal version in the repository — i.e. the same version than your website:

cd drupal
git tag            To list the existing branch names, i.e. the versions
git checkout DRUPAL-$VERSION-$CURRENT_RELEASE

By doing so, the drupal files in the directory ‘drupal’ are of the current release — this is the beauty of the ‘checkout’ command, you may select which release of the files you want to see or use.

Now, we’re creating a Git branch in which we’ll save your website:

git checkout -b $SITE
git branch          this should list both branches

The little star at the left of your newly created branch confirms that the command also switched the head to this new branch.

In this branch, we’ll replace the original Drupal files with yours we saved earlier in the temporary directory:

cd /var/www/$SITE/drupal
ls -l /var/www/$SITE/drupal/*          A check before the erase
rm -rf /var/www/$SITE/drupal/*
mv ../drupal-temp/* .

At this point, your website should run the same way as before. Now it’s time to commit your changes and tag the new branch:

cd /var/www/$SITE/drupal
git add .
git commit -m "`eval echo $SITE $CURRENT online`"
git tag -a \
    "$SITE-$CURRENT" -m "`eval echo ${SITE} ${CURRENT}`"      Tagging the new branch
git tag                This will list the tags

You now have a perfect setup for future Drupal upgrades.

Tags:

Add new comment

Wiki Textile Syntax

  • You can enable syntax highlighting of source code with the following tags: [code], [blockcode], [asp], [linux], [c], [cpp], [c#], [delphi], [dos], [f#], [html], [ini], [java], [javascript], [mysql], [perl], [php], [postgresql], [python], [ruby], [sql], [text], [vb], [xml].
  • You can use Textile markup to format text.
  • Web page addresses and e-mail addresses turn into links automatically.

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.