How to use patches instead of stashes

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the git category.

Last Updated: 2024-03-02

Say you have some changes that aren't committed and you want to merge in some remote changes. git stash is the normal way to persist these changes prior to merging, but it can be a bit clunky. Here's another way:

1. Generate the patch:

git diff > changes.patch

2. Later apply the patch:

git apply changes.patch

Another use-case of patches is to move git changes around between two repos when they are not connected via internet. Just put the patches on a USB stick.