Git copypasta
However let’s suppose you already made just a few tweaks on the remote system. Maybe you were testing there, and now your tests show that your edits are “good”. Now you want to properly push to production.
“I don’t always test my code, but when I do, I do it in production”
– Hopefully Not You
What is the quickest way to copy those working edits?
Here’s one way to do it with plain old copy and paste.
Note: this assumes your remote code is in a Git repository!
- Open a console on the remote system
cd
to the remote Git repository directory- Show the code differences
git diff
- Select the output
- Copy
- Mac OS:
cmd-c
- Unix/Windows:
ctrl-c
- Mac OS:
- Open a local console
cd
to your local Git repository directory- Prepare to apply the differences
git apply -
- Paste
- Mac OS:
cmd-v
- Unix/Windows:
ctrl-v
- Mac OS:
- Type
ctrl-d
- Verify locally
git diff
Updated – Apr 10
I changed git apply - <
to git apply -
. The extra <
would have read from a file, but I wanted to read from stdin.
Noticed after awkwardly trying to use this and wondering why it didn’t work😳.