Discuss Home · Bootstrapped Podcast · Scribbleton Personal Wiki · HelpSpot Customer Service Software

Looking for Git tips for solo developer who uses multiple machine


#1

I recently switched to Git from Subversion, mainly because I wanted to have a local copy of my repository so that I could compare with history quickly and without a good Internet connection. I’m having to relearn some habits…

Here’s the situation for which I need tips: I work about half the time in my office on an iMac. I work about half the time at home or on the road on a MacBook Pro. I’ve created a private Git repository on GitHub, and cloned it on both machines.

When I move from working at home on a task to working in the office on the same task, I want to easily be able to have the same files in the same state go with me, without having to remember to do a “push”. Does Git accommodate this? Should I get in the habit of automatically pushing after committing?

I ask because right now I’m in the office, and frustrated that I can’t continue with the task I was doing last night at home, because the current state of the files is not represented in GitHub, because I didn’t “push”.

And in general, what Git tips do you have that will work with my two computers that are not co-located?


#2

Pushing after committing would be the easiest solution. You could look at getting a Git GUI such as Tower or Github’s own Mac app if that would make it easier for you. Your IDE may have Git/Github integration either directly or through a plugin which might make it even easier.

Another possibility is investigating keeping your local Git repository in a Dropbox folder or even on a USB drive you carry with you. I’m not sure of all of the ramifications of those, though.


#3

When I was doing this, I had a gohome.sh script that would attempt to push all known git repos. I would run this every day before going home.

In your case, getting in the habit of pushing after every commit, and having a doneForNow.sh script that attempts to push before you leave your home desk or before you go to sleep etc.

As a Last Resort, you can do things like set up BackToMyMac or VNC. Slightly less bandwidth intensive is to have your entire git repo in a Dropbox or similar sync service.

I would be careful about automatic sync however. it’s kind of easy to have dropbox hose a git repo, especially when one is a laptop w/ occasional periods of non-connectivity. a sane dir structure helps:

$HOME/Dropbox/imac/repo
$HOME/Dropbox/laptop/repo

essentially, both repos are synced to both machines. On the iMac just work out of the imac dir and push pull as required.

If you find yourself at the office, temporarily drop into the imac dir and you can do a push. just make sure to pop out back to the laptop dir, especially if working from a coffee shop or somewhere with no internet.


#4

Yeah, you just have to push. Also, then everything is backed up which is nice. We use Tower which is also nice, some people like the Github mac client. It’s not bad and is one less button push, but lacks some other useful features.

People do put their code in a dropbox folder, though as is Dropbox sucks a lot of my battery and all that constant checking and uploading of changed states seems like it could cause trouble. I’d also be slightly concerned about the git repo files themselves getting into some odd states if you have one that was synced to dropbox, then work offline on another machine and what happens when they sync up, etc.


#5

Pushing is most safe way to sync through git, and preparing a doneForNow.sh script is a nice way to make it easier to not forget it.

Git also makes it really easy and fast to manage many different branches (I find it also more reliable than subversion when merging), so it is very convenient to have a branch for ongoing work separated from your ‘master’ branch, where you could commit and push partial work. You may push to the working branch as often as you’d like, and use that for synching between the two machines and then merge into the master branch when done.
Otherwise you may use single feature branches (i.e. have a branch where you just work on a single feature).


#6

@Imea,

Do you by chance have a sample doneForNow.sh script I can use?


#7

I haven’t got one at hand, but I think that something as simple as this may work:

#!/bin/bash
# N.B. this script will push all the committed changes to the remote repository

# This is the working copy (on your computer) 
WORKING_COPY=/home/user/work/project

# The remote name is usually 'origin', probably you won't need to change it
REMOTE_NAME=origin

# This is the name of the branch on the remote repo 
# it doesn't need to be equal to the name of the branch on your
# local repo, but I usually keep the same to make less errors
# when pushing
REMOTE_BRANCH=officesync

cd $WORKING_COPY
git push $REMOTE_NAME $REMOTE_BRANCH

Also you may find useful this script I have to configure the shell prompt https://gist.github.com/luca/6827108
I use git from the command line and that tells me immediately the branch I’m in and if there’s something to commit ( it puts an asterisk at the end of the branch name )


#8

If you’re on github, you can easily fork the main repo to create your own private remote. Then you can push and pull from that as much as you want without littering up the main repo. Branches are a simpler way to do this, but everybody else will have access to your WIP.

I don’t think there’s a way to avoid pushing, unless you use some outside tool. Though once you’ve forked the main repo, you can push early and often.

In my own experience I’ve found that a normal git workflow involves creating a separate little sandbox for your feature, doing lots of little commits and pushing at the end of each coding session. Whereas back in subversion, people would work on big changes locally for a long time before committing.


#9

Slightly off topic but I think pretty helpful: this game to learn Git, and in particular branching. It’s actually a lot of fun and a great way for people who are new to Git to get to grips with it’s concepts. Even when you normally use a GUI, it’s great to know what’s actually going on and what’s actually possible.


#10

A simpler solution for you right now sounds like just pushing after a commit. What is the problem doing that? I used to do that but would forget a push at home and be SOL wherever I was working remotely on it, which is not ideal. My solution is below:

I’ve been working on a side project where I needed to have my project “ejectable” from my work machine. So I just have it on a USB stick. I basically just carry it with me wherever I go and am able to pop it into whatever computer I want to work on it. I’ve had 0 problems.

The only risk is losing the disk, but you should be pushing regularly anyway.

Update 12/06/2013:

Just a note on my reasoning. I work a day job that probably wouldn’t like my working on a side project at work. GIven that I do not use solutions that require me to log into services that clone files locally (i.e. dropbox). The thumbdrive solution works for me and keeps everything in one place. I can keep it up to date and pop it in at home and push up to a remote vcs.

I’m not sure this answers the original question 100% but I’ll just throw it out there for anyone bootstrapping with a day job. Good luck!


#11

I just put my files and the git repo in a dropbox folder. That way the files are in the same state all the time on both of my synced machines. I commit and push - to Bitbucket in my case - from both of them. Never had any problems in years.


#12

My solution to this situation was a bit different. I had a big screen, keyboard and mouse and both locations and just carried the MacBook Pro between home and office.

Syncing is such a PITA. I decided I couldn’t deal with that on a daily basis, so just carried one machine with me everywhere.


#13

Yeah, the laptops are so powerful now that I’ve moved to the one machine solution and just use the Laptop everyone. Simplifies everything. Less stuff, less backups, less things to break, everything is always with you.


#14

I clearly must have been doing something wrong all this time. I’ve been on a laptop since my high school graduation present was an awesome Gateway 2000, 386 75mhz DX4 8MB of RAM and the largest screen you could buy, 10.1 inches. All that for a mere $3,500.

These days it’s a Macbook Air with 8 gigs of RAM, but it’s almost the same thing.

For the purposes of this discussion. Even though I’m on a single machine to do all my work and don’t work with a team at this time. I pretty much push every time I commit. And also, my working directory is on dropbox, but that is just for additional backupability. For me to lose all my work, github/my laptop/my time machine/and dropbox would all have to fail simultaneously. Not to mention the deployed code on the servers.


#15

I think the canonical way to automatically sync two repos is with a commit hook, built into git. It is very easy to automatically push from local to remote with every commit. This might be slightly slower, and may litter the repo with too many minor commits. But as a bullet proof backup, that is the way to go. I can clean up the commit trail later. I haven’t ever implemented the remote hook, as I seem to always remember to do a final push to remote at the end of any coding session. I don’t consider I’m done for the session unless I’ve committed locally and pushed to some remote as a backup. Belt and suspenders. I don’t trust any single hard disk. A couple of weeks ago, I was debugging a WordPress plugin on a VPS, with a local repo on that host. I would commit and then push to remote at the end of a session. My “budget” VPS hosting company vanished off the internet without notice recently, but my code was safe.

I’m pretty cheap, and refuse to pony up for private repos at Github, at least as long as I don’t need any collaboration tools. For a long time, Assembla was my spot, with unlimited private repos and up to 2GB of storage. I have 29 private repos there. Alas, a few months ago they stopped allowing unlimited private repos, though they aren’t throwing existing repos off their service. I’m migrating to Bitbucket, and “git clone --mirror” is useful for moving a remote repo with all its branches. I am most comfortable when my repos are backed up on two separate cloud services, and these days there are a lot of free private git repos to chose from:

https://git.wiki.kernel.org/index.php/GitHosting


#16

When I was working on Mac and PC at the same time I set up Dropbox to sync everything. This way you can commit code, or not, and all of your environments would be the same. I’ve made a blog post with the steps here. You can turn off the sync until you are ready to move to the other computer.

I’ve since moved to a single Mac laptop setup with a larger second monitor. Working on a single computer is a lot easier. I hope the link helped!