Drupal Tutorial - Upgrading Drupal Core on your websites with Git
Objective
In this Drupal tutorial I will outline how to upgrade your Drupal website from one version to the next using Git. This applies to both Drupal 6.x and Drupal 7.x, as well as, any future versions. This deals with the Drupal core files and not the database. Before you trying this, you should backup your database.
What Drupal.org has to say
The standard procedure to upgrade Drupal to the latest release is to download it from drupal.org and follow the included UPGRADE.txt. However if you have a GIT repository, it may not be as easy to follow.
How to create a Git repository of your website
-
Create a local Git repository in your application for your local files
#On local machine
cd /var/www/drupal_project
git init
git add *
git commit -m 'My initial commit message'
# Note: this method will not add .htaccess and .gitignore to your repositoryIf you are reading this, mostlikely you have done this. This is okay. Continue.
-
Create the repository on your Git server. This may be local or remote.
mkdir ~/git-repos
cd ~/git-reposCreate your new project git repo as a bare Git repository
mkdir drupal-project.git
cd drupal-project.git/
git --bare init -
go back to your local repository, and add the newly created remote repository so it tracks from the remote repository (origin).
#On local machine, and your git remote is on the same server.
cd /var/www/drupal_project
git remote add origin ~/git-repos/drupal-project.git#On local machine, and your git remote is on a remote server.
cd /var/www/drupal_project
git remote add origin ssh://currentuser@example.com:~/git-repos/drupal-project.git -
If you are on git 1.7+ you can simply run this command:
git push -u origin master
How to upgrade Drupal core without taking your website offline
-
Assuming your repository is a live, and you do not want to break it, clone the repository into a new directory
#Repository is on the same server
git clone ~/git-repos/drupal-project.git ~/temporary-project#Repository is on a remote server
git clone ssh://currentuser@example.com:~/git-repos/drupal-project.git ~/temporary-project -
Download the latest version of Drupal. If you have drush you can run this command:
cd ~/temporary-project
drush dl drupal
#You will now have Drupal installed inside your project ~/temporary-project/drupal-7.X -
Remove the Drupal core files. You need to remember which files you have customized and not remove them. Files that you may have customized.
Usually you will have to delete all files except my /sites directory as that is where all of your custom files resides.
# ~/temporary-project
rm ./includes -r
rm ./misc -r
rm ./modules -r
rm ./profiles -r
rm ./scripts -r
rm ./themes -r
rm ./* -r- .htaccess file
- .gitignore file
- robots.txt file
- settings.php file (sites/all/default or sites/all/example.com)
- custom profiles (profiles)
- custom themes (sites/all/themes)
- custom modules (sites/all/modules/custom)
- contributed modules (sites/all/modules/contrib)
- custom features (sites/all/modules/features)
-
Remove customized files and directories from the latest version
# ~/temporary-project/drupal-X.X
rm ./sites -r -
Move the lastest version into the current directory and remove the left over directory
# ~/temporary-project
mv ./drupal-X.X/* ./
# this will not move .htaccess or.gitignore. If you want them then you you have
# to move them seperately
rm ./drupal-X.X -r -
Add the new files and commit the changes
# ~/temporary-project
git add -u
git status
# if there is new files you will need to add them manually
######### Example Output ########
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# drupal-7.15/
# modules/simpletest/tests/entity_query_access_test.info
# modules/simpletest/tests/entity_query_access_test.module
# modules/simpletest/tests/themes/test_basetheme/
# modules/simpletest/tests/themes/test_subtheme/
#
######### End of Example Output ########
git add modules/simpletest #this will add all the untrack files in modules/simpletest
git commit -m 'upgrade to version X.X'
</file> -
Push the changes
# ~/temporary-project
git push -
Pull the changes to production/live
# /var/www/drupal-project
git pull -
Don't forget to run update.php!
Alternative methods to upgrade Drupal core
- Run Drush command
drush up drupal.
- Apply a patch of the differences between the versions. See http://drupal.org/node/359234 There is a link off that page to an external website with all the pre-made patches.
Comments
Thank you
Thanks! Very clear instructions now that I've read a bit about git.
Add new comment