---
title: "How to apply and test a patch from drupal.org using Git on Acquia Cloud"
date: "2022-03-16T19:54:58+00:00"
summary:
image:
type: "article"
url: "/acquia-cloud-platform/help/92576-how-apply-and-test-patch-drupalorg-using-git-acquia-cloud"
id: "730fcc94-a17c-4ecd-bf88-a8f8f281cc5b"
---

Code doesn't always work the way you expect it to. Sometimes you're going to have to use a patch.

Important

Acquia's [Remote Administration (RA)](/node/55865) service requires customers to follow specific steps when applying patches, to make sure that changes are not overwritten by RA updates. For more information, see [Patching and locking modules](/node/56162).

Important

If you are using Drupal 8 and above using Composer please see [Patching and locking modules](/node/56162).

Here are the steps for applying and testing a patch to a contributed module in your development environment on Acquia Cloud while using Git. These directions are also applicable to SVN users, but the repository-specific commands are different.

Note

For information and resources about Git, see the [Git basics](/node/92996) article.

1.  Sign in to Acquia, and then view your environments on the **Cloud > Workflow** page.
2.  [Back up your database](/node/56287). (You can also use this as an opportunity to [back up your website's files](/node/56287))
3.  [Copy your production database back to the development environment](/node/56311).
4.  Clone (if necessary) and check out your repository, based on if you have cloned it locally or not:
    *   _If you have not cloned your code repository locally_, do that now. The following command will clone your repository and check out the production tag:
        
            git clone [site_Git_URL] [your production tag name]
        
        The repository folder is created wherever the command line was when the `git clone` command was run.
        
    *   _If you have already cloned your code repository locally_, check out your production tag from your local Git repository location.
        
            git checkout [your production tag name]
        
5.  Change the directory to be inside the repository folder that you just created.
    
        cd [repositoryname]
    
6.  Create a new branch locally.
    
        git checkout -b [new descriptive branch name]
    
7.  If this is a patch for a contributed module, change to that module's directory.
8.  Apply the patch.
    
    You can download the patch to a temporary location such as your docroot's temp directory:
    
        curl -s https://www.drupal.org/files/issues/[patch_name].patch > /tmp/patchfile.patch
    
    Run a test to ensure the patch will apply cleanly.
    
        patch -p1 --dry-run < /tmp/patchfile.patch
    
    If this returns positive results, you can then apply the patch and remove the file.
    
        patch -p1 < /tmp/patchfile.patchrm /tmp/patchfile.patch
    
    Note
    
    You can also combine all of these steps into a single command, which executes the test and applies the patch if the dry run completes normally:
    
        # The && syntax ensures the next command only runs if the previous one was successful.curl -s https://www.drupal.org/files/issues/[patch_name].patch >/tmp/patchfile.patch && patch -p1 --dry-run < /tmp/patchfile.patch && patch -p1 < /tmp/patchfile.patch && rm /tmp/patchfile.patch
    
9.  Commit the change locally.
    
        git commit -am \"Added patch for x issue\"
    
10.  Push the new branch to the git repository.
     
         git push -u origin [branch name from step 5]
     
11.  Change the branch in development to the new one you created. You can do this on the **Cloud > Workflow** page.
12.  Test the patch in the development environment.

After you have completed your testing, you can then move the code into production. For information about patching Drupal, or patching using Git or SVN, you can also visit the [Applying patches](https://www.drupal.org/docs/develop/git/using-git-to-contribute-to-drupal/applying-a-patch-in-a-feature-branch) page on Drupal.org. For general information about Git, visit [Git Immersion](https://gitimmersion.com/).