DEV Community

Cover image for How to create Magento 2 git patch and apply.
Navaneeth V
Navaneeth V

Posted on

How to create Magento 2 git patch and apply.

There are times where it is not possible to override an core function or a possible github fix for an issue in Magento, and you are not updating the current version to get the fix.
Times like these where git patches comes to the rescue.

The basic syntax for apply git patches
git apply <location-of-your-patch-file>

Suppose we are ought to modify the file
vendor/magento/module-customer/Block/CustomerData.php and create a custom patch.

  1. Create a copy of that file in the same location vendor/magento/module-customer/Block/CustomerDataModified.php
  2. Modify the changes in the new file and save it.
  3. At this point, the vendor folders are ignored and you want to force git to find difference between two files, so we run the command diff -u CustomerData.php CustomerDataModified.php > diff.patch This will generate a file 'diff.patch' in your root directory.

Top comments (0)

Image of PulumiUP 2025

Let's talk about the current state of cloud and IaC, platform engineering, and security.

Dive into the stories and experiences of innovators and experts, from Startup Founders to Industry Leaders at PulumiUP 2025.

Register Now

👋 Kindness is contagious

Dive into this informative piece, backed by our vibrant DEV Community

Whether you’re a novice or a pro, your perspective enriches our collective insight.

A simple “thank you” can lift someone’s spirits—share your gratitude in the comments!

On DEV, the power of shared knowledge paves a smoother path and tightens our community ties. Found value here? A quick thanks to the author makes a big impact.

Okay