Checking out tags from git on your server

Tags: django

Properly tagged and released: that, all our websites are. Most of them are subversion projects, but a handful are now in git. When switching to a new version of a site, the subversion process is clear:

$> svn switch https://our.svn.server/project/tags/1.2
$> bin/buildout
$> ...

And the next time:

$> svn switch https://our.svn.server/project/tags/1.3
$> bin/buildout
$> ...

What I did with our first git project (after an initial “clone” of course):

$> git pull
$> git checkout 1.2
... Dire warning about "headless state" as I checked out a tag ...
$> bin/buildout
$> ...

And the second time:

$> git pull
... polite notice to bugger off as we're in a headless state ...
... no, we're not going to do a pull! ...

Ok, what now? I asked around on twitter and got the luckily simple answer: use git fetch instead of git pull. Fetch fetches the last bunch of commits from the server. Pull does the same and additionally updates the checkout to the latest relevant version. Which it refuses to do if the current checkout is a tag.

A tag as such is not really connected to the main tree of development that git knows about. It is more of a light-weight pointer. You get a certain clearly identified version of the code, but that version you have is not really hooked up in to the git tree. It has no parent to point to, so it also doesn’t have a relation to some pointer to the latest version on this branch of the tree: the head. That’s where the “headless state” comes from.

git fetch just grabs the latest state from the server. And a subsequent git checkout 1.3 checks out the 1.3 tag without a complaint:

$> git fetch
$> git checkout 1.3
$> bin/buildout
$> ...
Signal box on a model railway (Dreimühletalbahn)
 
vanrees.org logo

About me

My name is Reinout van Rees and I work a lot with Python (programming language) and Django (website framework). I live in The Netherlands and I'm happily married to Annie van Rees-Kooiman.

Weblog feeds

Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):