Starting with git in a team of one March 19, 2008

Filed under: Linux — archiecowan (Follow on twitter) @ 7:32 pm
starting-with-git-in-a-team-of-one

I became a git fanatic quickly after hearing Linus speak. I had been using Subversion for only a few weeks when I saw the video — after using CVS for years. Not being all that impressed with Subversion, I was thirsty for something more. Git has basically become the way I version any project I start, track changes to system configurations, or even keep revisions of websites I host.

I use git on Mac OS X, Ubuntu and Gentoo. The installs on any of these systems are straightforward. Any day now, I’ll need it on Solaris, but that doesn’t look as easy. I’ll have to write later about Solaris. Here are the commands if you’re following along at home:

  • Ubuntu
    • apt-get install git-core git-svn gitk
  • Gentoo
    • emerge git
  • Mac OS X with MacPorts
    • port install git-core @doc @svn

Note, the git-svn stuff will install an add-on git component that allows you to work with svn repositories through git. I’ve just started experimenting with it, and I expect you will want to as well. Install it now and you will be happy it’s there when you get to it. The Gentoo packages include it by default. Note 2, gitk is super awesome. You’ll want to check that out later, too.

For starting a new software project, let’s say, a Ruby On Rails webapp, this is what a typical session might look like:

archie@baileys ~/projects/subprocess $ rails gitdemo
create yadda yadda
archie@baileys ~/projects/subprocess $ cd !$
cd gitdemo
archie@baileys ~/projects/subprocess/gitdemo $ cp /somewhere/.gitignore .
archie@baileys ~/projects/subprocess/gitdemo $ cat .gitignore
log
tmp
archie@baileys ~/projects/subprocess/gitdemo $ git init
Initialized empty Git repository in .git/
archie@baileys ~/projects/subprocess/gitdemo $ git add .
archie@baileys ~/projects/subprocess/gitdemo $ git commit
Created initial commit 56e64fa: Initial commit
44 files changed, 8341 insertions(+), 0 deletions(-)
create mode 100644 .gitignore
create mode 100644 README
create mode 100644 Rakefile
snippy snippy again
archie@baileys ~/projects/subprocess/gitdemo $

So the important parts of all that output are:

  • You create your project, maybe write some code.
  • git init will initialize a repository.
  • I keep a .gitignore file around that I use in all my Rails projects. It will usually include directories I don’t want in version control like tmp files or logs.
  • git add . will queue up any changes I’ve made to my new repository to be committed.
  • git commit commits to the repository.

This pretty much sums up how I use git by myself on a project. If you want a good tour of the excellent merging features of git and how to begin to work with a team, check out this tech talk by Randall Schwartz. He gets into the good details.

This is also the process I use to set up revision control on my system files and hosted sites. When I set up a new Linux server, I go straight to /etc and type git init, git add ., git commit. You can’t beat this kind of control over your system files, especially for the ability to roll back changes. This has saved the day more than once for me when someone has damaged their apache configuration files beyond repair. The same goes for the websites. I just go to the document root of the site and add a git repo there.

So, try git and tell all your friends. I’ll be back later to tell you about my git-svn experiments.

 

1 Comment for this post

 
benarwin Says:

If you’re really starting from scratch, you will need a few “git config” commands. My standard issue git configuration is as follows:

git config --global user.name "Your Name Comes Here"
git config --global user.email you@yourdomain.example.com

Those are required. The next ones will give you some pretty color for certain git commands (such as ‘git status’ and ‘git diff’):

git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto

Leave a Reply