Because we use a devOps system that installs packages on the server via Composer, my core drupal installation and contrib modules are not in version control (Git).

I used to patch modules as follows:

  • Commit everything, so my branch is up-to-date.
  • Make my changes to the module (= write the fixes in the module).
  • Inside my code editor go to Code -> Create patch and follow the steps there (because of Git, my editor knows what has changed).
  • My patch gets saved where I prefer to do it.

Since we started working with keeping modules and core out of Git I do not have a clue on how to create my patches anymore.

Curious about the solutions you might have!

  • 1
    See github.com/cweagans/composer-patches for the approved method. Commented Sep 6, 2019 at 15:19
  • It is not about how to apply it, but about how to create it (edited my question) Commented Sep 6, 2019 at 15:38
  • 1
    Follow the Making a Drupal patch with GIt documentation on d.o for how to create patches.
    – sonfd
    Commented Sep 6, 2019 at 15:43
  • 2
    @StefVanLooveren The answer is basically “however you want/can”, there’s no standardised process for doing something like what you’re describing. If this was forced on me I’d probably cobble together a couple of bash scripts that make copies of the site then run diff on them when required to. But it would be painful. Thing is, everything you’re talking about (Drupal and its contrib modules) lives in git already. So, arguably, you should create your patches using git, and make them available to your Composer workflow separately for installation
    – Clive
    Commented Sep 6, 2019 at 16:16
  • 2
    If the patch fixes an issue with a contrib module, then I always add or update a relevant ticket and upload the patch so it is available to others. The process is well documented on drupal.org. Commented Sep 6, 2019 at 16:52

1 Answer 1


So, you would have to download the module seperately, like:

git clone --branch 8.1.x http://git.drupal.org/project/colorbox.git

Then, you make the change and run the following:

git diff 8.1.x > colorbox-css-issue.patch

This creates a patch for this module. Now you can place the patch in a patches folder and add it to your composer.json file. Source: This blogpost

Update: created a small tutorial in this video

  • 1
    +1 upvote this answer (and the question) - this answer explains how to do it so simply and clearly. Helped me a lot, creating my patch for extending a contrib module. I'm also grateful for the docs on drupal.org but they can be verbose and not as easy to read as on here, Thank you! Commented Oct 20, 2020 at 22:28
  • Great solution. Can I use this approach also on D10? Commented Apr 16 at 14:48
  • @Farizio definitely Commented Apr 17 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.