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 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:
mv drupal drupal-temp
Install drupal by cloning the local Git repository (See the prerequisites if you don’t have a local Git repository):
Select the matching Drupal version in the repository — i.e. the same version than your website:
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 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:
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:
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.
Add new comment