Bob and Alice: a git patch love story
Sometimes, I need a silly story to help me remember the obscure; things I do not use or do very often. Like git patching via e-mail. Here’s a little love story.
---
Bob loves Alice. And Bob loves Alice’s git repository.
- Bob clones it.
-
Bob makes his changes and commits them normally.
git add . git commit -
Bob generates patch file(s) from his commit(s). This produces one
.patchfile per commit.git format-patch origin/main -
Bob sends the
.patchfile(s) via email as attachments. The attachment must be sent as-is (no inline pasting).
That is all that is required on Bob’s side.
Bob’s patch file is like a love letter…carefully crafted, full of intention, and best delivered intact. Signed, sealed, delivered, I’m yours!
---
Alice receives Bob’s patch via e-mail.
After careful consideration, she likes what she sees, and wants to take things forward.
Alice:
-
Saves Bob’s
.patchattachment(s) to disk. -
Ensures she’s on the target branch.
git checkout main -
Applies the patch(es) with Git, preserving metadata.
# For a single patch: git am bob-change.patch # For multiple patches: git am *.patch
Sometimes, love isn’t smooth sailing. If Alice’s repository has changed since Bob’s commit, Git might throw a conflict…like a misunderstanding in a relationship; a lover’s tiff, if you will.
Alice is kind, patient and understanding, so she checks the changes, resolves the conflicts, and commits to moving forward together.
-
If conflicts occur, she resolves them, then continues.
git status git add <resolved files> git am --continue -
If she decides to abort instead:
git am --abort
Hopefully Alice works things out with Bob.
After a successful git am, the commit(s) are in Alice’s branch with Bob recorded as the author.
A match made in heaven!
With the patch(es) applied, Bob’s changes live happily ever after in Alice’s repository. Together forever.
Fin.
