Transfer git Changes With a Pasteboard-Workflow
Sometimes you want to transfer changes you made to a source tree from one computer to the other. The source tree on both computers are managed by git. One reason to do this, is because you tried something on your laptop. But you changed your mind, and want to work on a desktop computer with a big screen and real keyboard. And you don’t want to re-type everything.
Another reason might be, because you debugged a problem on a production machine (I never do this, of course). The production machine only has readonly access to git. You want to secure these changes exactly, because they work.
The commands are pretty simple, but I keep forgetting them. The commands use the diff format. If possible, I try not to create temporary files, because often they leave a mess. If the source machine is on MacOS, I use this command to secure patch:
$ git --no-pager diff | pbcopy
When on Linux via ssh in a Terminal.app window, I copy by hand:
$ git --no-pager diff
# Press cmd+A to select output from last command, and press cmd+C to copy
With help of the universal clipboard, I can paste this on the target machine. But before I do that, I first check the status of the target repository:
# Checking if the index is clean, and we are on the right branch
$ git status
# Now we can apply the patch
$ pbpaste | git apply -
Now I can review and commit the changes, and push the changes to our origin. Normally I would use GitHub Desktop for this, because I like working with GUI’s for this kind of work.
After pushing, we have to cleanup things on the source machine. With older git-versions, you didn’t need to reset the working folder. But since I don’t know when this is necessary:
# Undo all the changes we secured in previous steps
$ git reset --hard
# Now get the changes
$ git pull
Finally you might want to restart any processes that need restarting.
You can of course use temporary files. Files are more reliable anyways.