Git push directly to another workstation
You don’t need GitHub to work with git on multiple computers, and you don’t even need a git remote set up to do it.
Sometimes I’m working on some code that is incomplete, or is speculative, or there’s another reason that I don’t want to push it to the remote branch yet, but I need to swap from my desktop to my laptop or vice versa.
Git is a distributed version control system, but I think people often forget
what that implies. A git repository can be as simple as a directory available
via ssh, which means that your other computer is already a git repository
as long as you can ssh to it.
Furthermore, you don’t have to go through the ceremony of setting your other
computer up as a named git remote; if you can ssh to it, you can access it
directly using a properly-constructed URL:
git push ssh://mylaptop.local/~/path/to/repo
You can do this for pull, push, fetch, and any other command where you’d
normally use a named remote.
There are some caveats:
- The remote directory has to have a git repository already; if not, you’ll
have to
sshin and create one withgit init path/to/repo(it will even create the intervening directories for you). - You can’t (by default) push to the currently active branch on the remote; create or use a different branch instead.
But most of the time, I’ve already been working on the same codebase on the other machine. I have something that isn’t quite ready yet, so I make a work-in-progress commit on a new branch, send it across, and pick up where I left off.