If you are working on Drupal projects then you most probably know the patches. In Drupal, if you find a bug in the contributed module or add a new feature in the contributed then you create the patch and upload it on drupal.org for the community.
Here are steps how you can create a patch.
My current directory structure.

Create patch via git:
Step 1: Add your changes in the contributed module e.g modules/contrib/seo_hreflang)
Step 2: Once done then download fresh contributed module again in separate patches directory via wget .
e.g
wget https://ftp.drupal.org/files/projects/seo_hreflang-8.x-1.x-dev.zip
Step 3: Extract the module and then go to directory
unzip seo_hreflang-8.x-1.x-dev.zip
cd seo_hreflang
Step 4: Add the changes into git. Execute the below commands
git init
git add .
git commit -m "Initial code changes.
Step 5: Copy the modified module all files and paste into fresh download module directory.
cp -a ../../d9313/web/modules/seo_hreflang .
Step 6: Your patch name should be like [project_name]-[short-description]-[issue-number]-[comment-number].patch as mentioned on https://www.drupal.org/docs/develop/git/using-git-to-contribute-to-drupal/patch-and-merge-request-guidelines#naming-conventions
Step 7: Create patch e.g
git diff > seo_hreflang-fix-compatibilty-issue-3282026-0.patch
Apply the patch via composer:
Composer use *cweagans/composer-patches* plugin for patch installation. Please make sure before applying patch it is install. You con checkout either cweagans/composer-patches is in the composer.json or not.
If not then use the below command to install it
composer require cweagans/composer-patches
Step 1: Go to Drupal project directory & edit the composer.json file
Step 2: Go in "extra" section of the composer.json file and add the patches entry if it is not already there e.g
‘extra’ : {
“patches” : {
"drupal/seo_hreflang": {
"Non-existent service path.alias_manager": "https://www.drupal.org/files/issues/2022-05-24/service_change-3282026-5.patch",
"User inserted values only": "./patches/seo_hreflang-Non-existent-service-issue-3282026-4.patch"
}
}
}
Note: "patches" directory is in the Drupal root and patch file seo_hreflang-Non-existent-service-issue-3282026-4.patch is in that directory.
Step 3: Use the below command to apply the patch
composer install