Upgrading a Drupal site with Git
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.
In this article I’ll show you how to upgrade a Drupal website easily, thanks to Git (on a Linux server).
Upgrade your local Drupal Git repository
It’s a simple task you could run regularly in a cron job:
git pull
Prepare your upgrade
In this example we’ll suppose you want to upgrade from Drupal 6.22 to Drupal 6.23 — of course, you should set the following variables to your configuration:
export CURRENT_RELEASE=22
export CURRENT=drupal-$VERSION.$CURRENT_RELEASE
export NEW_RELEASE=23
export NEW=drupal-$VERSION.$NEW_RELEASE
This is the website I’m upgrading — Change to your configuration accordingly:
export DB=notes_telagroup Name of the database
We’re setting some additional variables:
Some backups
ls -l
- Backup MySQL
mysqldump -u root -p $DB | zip > $DB.sql.$CURRENT.$DATE.zip
ls -l
- Commit changes
Look at the Git status to check if you made some changes which were not committed:
git status
If positive, do a commit:
The upgrade
Now it’s time for the upgrade. The Git command ‘merge’ will do it:
git merge DRUPAL-$VERSION-$NEW_RELEASE
git status
To look at the changes, use the diff feature found in Git. This will list the differences made by the Drupal team:
To see the differences you’ve made since the last merge, run this command:
I usually put a comment with my name “ericdes” or “tela” on all the change I make to the code, this allows me to retrieve them quickly with these commands:
git diff —ours | grep tela
Resolve the conflicts
You’ll probably face some conflicts, here’s how to resolve them (3 methods):
- Manually
export file=CHANGELOG.txt Replace with a conflicting file name
nano $file Correct the conflicts
–
git add $file
- Overwrite with our release
(git 1.6.1 and up)
export file=sites/default/settings.php Replace with a conflicting file name
git checkout —ours $file
git add $file
(or)
export file=sites/default/settings.php
git reset — $file
git checkout ORIG_HEAD — $file
git add $file
(or, use our script)
~/git-overwrite-with-our-release sites/default/settings.php
- Overwrite with their release
(git 1.6.1 and up)
export file=CHANGELOG.txt Replace with a conflicting file name
git checkout —theirs $file
git add $file
(or)
export file=CHANGELOG.txt
git reset — $file
git checkout MERGE_HEAD — $file
git add $file
(or, use our script)
~/git-overwrite-with-their-release CHANGELOG.txt includes/cache.inc includes/common.inc
Do this for all conflicting files, and verify:
Once all conflicted have been resolved, you want to commit:
git tag -a \
"$SITE-$NEW" -m "`eval echo $SITE $NEW`"
Now it’s time to update the database:
Check that your website is running the new Drupal version!
Add new comment