How to create patch using Git and apply it.

To create a patch

git diff > changes.patch

The above command will not include new files that are untracked. So to track these files. Add them to the staging area as shown below

git add <filename> # or
git add .

then use the following command to create patch

git diff --cached --binary > changes.patch

use --binary to include binary files to the patch.

To apply the patch

git apply changes.patch

You can also see what will be changed by the following command:

git apply changes.patch --stat

You can also use patch command as follows. To learn more, see the man pages and sources below.

patch -p1 -b -i changes.patch

Important to know

git diff for unstaged changes.
git diff --cached for staged changes.
git diff HEAD for both staged and unstaged changes.

Source(s)