Add new comment

Drupal Tutorial - Upgrading Drupal Core on your websites with Git


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 has to say

The standard procedure to upgrade Drupal to the latest release is to download it from 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

  1. 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 repository

    If you are reading this, mostlikely you have done this. This is okay. Continue.

  2. Create the repository on your Git server. This may be local or remote.

    mkdir ~/git-repos
    cd ~/git-repos

    Create your new project git repo as a bare Git repository

    mkdir drupal-project.git
    cd drupal-project.git/
    git --bare init
  3. 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://
  4. 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

  1. 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:// ~/temporary-project
  2. 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
  3. 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/
    • 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)
  4. Remove customized files and directories from the latest version

    # ~/temporary-project/drupal-X.X
    rm ./sites -r
  5. 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
  6. 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 &quot;git add <file>...&quot; to include in what will be committed)
    # drupal-7.15/
    # modules/simpletest/tests/
    # 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 &#39;upgrade to version X.X&#39;
  7. Push the changes

    # ~/temporary-project
    git push
  8. Pull the changes to production/live

    # /var/www/drupal-project
    git pull
  9. Don't forget to run update.php!


Alternative methods to upgrade Drupal core

  1. Run Drush command drush up drupal.
  2. Apply a patch of the differences between the versions.   See  There is a link off that page to an external website with all the pre-made patches.

Filtered HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Web page addresses and e-mail addresses turn into links automatically.
  • 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.
By submitting this form, you accept the Mollom privacy policy.