I got two Git repositories which diverged too much, so when I fixed a bug in one repository, the same fix should be applied to the other repository.

The workflow is:

1. Create the patch.

Use git format-patch -1 <sha> to create the patch from git commit. <sha> is the SHA1 of the commit.
For the latest commit, we can use git format-patch -1 HEAD.

2. Check the patch

Use git apply --stat <patch file> to get the stats after applying the patch. Use git apply --check <patch file> to check any errors.

3. Apply the patch

Use git am < <patch file> to apply the patch and commit.

4. When conflicts

When the patch cannot be applied due to conflicts, use git apply --reject --whitespace=fix <patch file> to apply the patch partially. Unapplied changes will be put into *.rej files. Resolve the conflicts yourself and commit the changes.