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”
Admin who tested 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!

  1. Open a console on the remote system
  2. cd to the remote Git repository directory
  3. Show the code differences
    git diff

  4. Select the output
  5. Copy
    • Mac OS: cmd-c
    • Unix/Windows: ctrl-c
  6. Open a local console
  7. cd to your local Git repository directory
  8. Prepare to apply the differences
    git apply -

  9. Paste
    • Mac OS: cmd-v
    • Unix/Windows: ctrl-v
  10. Type ctrl-d
  11. 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😳.