As a follow up to yesterday’s git post, I wanted to share one other Git trick.
SVN is client-server. Git is multi master. Which means that you can easily share your code between your laptop and desktop without ever touching the outside world, though you will need SSH enabled on both machines. Here’s how to do it.
On Your Desktop
git remote add laptop <username>@<laptopname>:/path/to/git/repo
git fetch laptop
On Your Laptop
git remote add desktop <username>@<desktopname>:/path/to/git/repo
git fetch desktop
Moving Code
Once you’ve got the remote set up, it’s no different than doing a git pull
from the central server.
To pull from the laptop to the desktop:
git pull laptop <branchname>
To pull from the desktop to the laptop:
git pull desktop <branchname>
Never Push in this Case
If you go with this setup, always pull from the other repo. It is never a good idea to push to a repository with an active working copy. Unexpected things can happen and it’s possible to lose commits. Pulling is always safe, since you are actively managing the side that is changing from the operation.