An abridged day with Git

Let's walk through my daily workflow, up to the point where I'm ready to commit back to my upstream SVN repository.

Since I work on a fair number of branches and I don't always know what I worked on last, I run git-status to see which branch I'm in, and any uncommitted work. This command shows my current branch, uncommitted files, and files in the index cache1.

I like to keep my tree as fresh as possible, so I'll next run git-svn rebase to update my tree with the latest from SVN. You can't run a rebase, however, if your working tree is dirty, so I'll clean up what I can using git-commit and git-add --patch2. Any code I can't fold into a commit, I put aside for a moment with git-stash.

When the rebase is completed, I'll put any stashed code back with git-stash apply. Now my tree is up-to-date, and I have all my local changes worked into it.

The rest of the day proceeds pretty normally. I hack on code, and I'll commit whenever I see fit (which is often - as I've mentioned, I'm a Machine Gun Committer).

We haven't committed any of this back to the SVN repository yet, but in the next article we'll cover that, along with how I fool my coworkers into thinking I magically do everything in one commit, even though I've actually committed very frequently.

  1. Git's index cache (a.k.a. Staging Area) is an intermediate location between the Git repository and the current working copy. Coming from SVN, this will appear a little baffling to you, but it exists as a way to manipulate commits before generating a patch. You add files to the cache using git-add and git-commit commits everything in the cache to the repository.
  2. git-add --patch, along with git-rebase -i branch, are some of the most useful and world-shaking things that come with git. In a future article I'll take a look at both of these commands to highlight some of their utility.