Create patch messages to apply into other repos, like old-school pros
Overview
This is a hands-on tutorial on how to use Git patch from the command line and in a Bash script.
NOTE: Content here are my personal opinions, and not intended to represent any employer (past or present). “PROTIP:” here highlight information I haven’t seen elsewhere on the internet because it is hard-won, little-know but significant facts based on my personal research and experience.
Man page
- On a Terminal, to see Git’s documentation on the git patch command:
man git-patch
A Git patch file is a mail document which updates a Git repository using the git am command instead of a git commit command.
This approach is used by Linux Core developers.
PROTIP: This can be a scary operation, so I’ve written a Bash script to make it easier, faster, and safer.
-
In an internet browser such as Google Chrome or Mozilla Firefox, visit my Bash script “git-patch.sh” at:
https://github.com/wilsonmar/git-utilities/blob/master/git-patch.sh
The Bash scripting in the file is explained in:
https://wilsonmar.github.io/bash-coding and in this document.The script “git-patch.sh” clones a repo, creates a patch, opens another repo, and applies those changes.
NOTE: Thanks to Prem Sichanugrist for his blog about git patch of piping several messages into a single patch file.
Git Branching Model
Git patches are used by the Git core team branching model is described in this Oct 21, 2016 video by Nicola Paolucci when he was a Developer Advocate at Atlassian.
- np/topic branch are discussed using patches emailed
- pu = proposed updates
- next branch are changes about to be merged into master
- next and maintenance branches are reset after releases
More
This is one of a series on Git and GitHub:
- Why Git? (file-based backups vs Git clone)
- Git basics (script)
- Git whoops (correct mistakes)
- Git command shortcuts
- Git interactive merge (imerge)
- Git patch
- Git utilities
- Git hooks
- GitHub data security
- GitHub actions for automation JavaScript
- GitHub REST API
- GitHub GraphQL API
- GitHub PowerShell API Programming
- GitHub GraphQL PowerShell Module