Tuesday, June 10, 2008

It's GIT'ing better all the time.

  • I have some source code that I need to share between a desktop and laptop sporadically.
  • When I'm working on the code on the laptop (potentially disconnected from any network for several days), I want all the same scm style capabilities (tagging, branching, roll-backs) that I get when I'm working on the desktop.
  • I don't want the overhead of maintaining a server securely or paying for a hosted solution.
  • I'll only ever be actively developing on either the laptop or desktop at any given time, so merges are no concern [for now].
After watching the ever opinionated Linus, a few git casts, and reading Wincent's summary, I was gung-ho convinced GIT could do the job.

GIT Recipe #1. One-way pushes between two trusted peers.

Base dir

|-> Myproject dir

Step 1. Create a GIT repo and index on machine #1 for your project.
machine1$ cd /myproject
machine1$ git init
machine1$ git add .
machine1$ git commit

Step 2. Start the git server component on Machine #1. Warning this allows fully anonymous unauthenticated access, so only do this in a secured LAN environment -- and personally, I would only do it for short sporadic bursts of time even in that environment. For a more secure option (i.e. - apache/ssh/etc), see the git docs (it's a bit more work).
machine1$ git-daemon --verbose --export-all --enable=receive-pack --base-path=/parentof/myproject/dir

Step 3, clone the repo to machine 2.

machine2$ git clone git://machine1/myproject

To do work on machine 1, and send the updates to machine 2

On Machine 1 (origin repo), remove a file and commit the change.
machine1$ vi README.txt
machine1$ git add README.txt machine1
machine1$ git commit

On Machine 2, pull those changes across

machine2$ git pull

To do work on machine 2, and send the updates to machine 1

Make some change . . .
machine2$ vi README.txt
machine2$ git add README.txt
machine2$ git commit

Push those changes over to the origin repo

machine2$ git push

Then, on Machine A [be careful not to have any local changes], to get those changes into your working copy:
machine2$ git checkout -f

Bottom-line: The big benefit here is that I can commit, tag and branch at will on either machine without them being connected, and then sync them up when there is connectivity. There are git workflows which allow for that capability with larger groups, but I personally only need this one workflow (working while disconnected) to function at the moment.

Some of the better GIT Resources I've found:
  1. http://rails.wincent.com/wiki/Git_advantages
  2. http://www.youtube.com/watch?v=4XpnKHJAok8
  3. http://www.sourcemage.org/Git_Guide
  4. http://www.gitcasts.com
  5. http://www.rockstarprogrammer.org/post/2008/apr/06/differences-between-mercurial-and-git/
  6. http://cheat.errtheblog.com/s/git
  7. http://cheat.errtheblog.com/s/git_usage/
  8. http://ktown.kde.org/~zrusin/git/git-cheat-sheet-medium.png
  9. http://code.google.com/p/git-osx-installer/
  10. http://www-cs-students.stanford.edu/~blynn/gitmagic/index.html
  11. http://google-opensource.blogspot.com/2008/05/develop-with-git-on-google-code-project.html
  12. http://osteele.com/archives/2008/05/my-git-workflow
  13. http://ktown.kde.org/~zrusin/git/git-cheat-sheet-medium.png
  14. http://www.dekorte.com/blog/blog.cgi?do=item&id=2539

No comments: