Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to Create and Apply a Patch w/ Git Across Similar Repositories
## In your origin repo that contains the changes you want patched onto similar repos
#
# A "similar repo" might be one that was using the same codebase in the past, but was not forked
# If you have been working on a feature branch, just grab all commits different between the branch and master
git format-patch master
# Or, if you would like to grab the last few commits that make up a feature change...
git format-patch -2
# ...where "-2" is the number of commits you'd like to go back in history and create patches for
# This will create a patch file for each commit
# DO NOT run both of these commands
# Assuming your patch files have been moved into the root directory of the project where they will be applied...
# Check the changes in the patch
git apply --stat 0001-my-changes.patch
# Check that the patch can be applied
git apply --check 0001-my-changes.patch
# Apply the patch
git am --signoff < 0001-my-changes.patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment