(Git) Create & apply patch

  1. Create git patch file: After making changes to source code, write contents of git diff to a file:
    git diff [--cached] [<SOURCE_FILE_SUBSET>] > <PATCH_FILE_PATH>
    
  2. Apply the patch file in another branch where needed: git apply <PATCH_FILE_PATH>

References:

Written on March 15, 2021