back to list

Git tag it like it’s hott

  October 08, 2009 — written by Chris Sloan | 0 comments »

At Real Travel we practice SCRUM which allows us to release a new code base to the live server roughly every two weeks. Since moving to Git we now are able to track our releases in a more methodical manner using the git tag command.

The idea behind tagging

Take this scenario: your development team has just released to the live server what they thought was a bug free code base, but your QA team raises a red flag on a bug they just found. After they had released, the development team jumped onto the next project, building on top of the current code. Luckily, the development team tagged the release and are able to "go back in time" and find that bug without affecting their current work.

Tagging is like a sticky note in a text book that you can easily turn to for future reference. Whether it is to fix a bug or maybe even branch off a known stable release, it's like the DeLorean for git.

The tagging solution

The following is an example how the development team above was able to fix their bug and release it with out any problems. Please note: the following code is examples on how to tag your local branches. Tagging directly on a remote branch is covered later below.

After the team released, they tagged the master branch:

$ > git tag release_3 master

Note: a tag name cannot contain spaces, ~ ^ : ? * [ ] or ASCII

Doing a git tag command without any parameters will list out all the current tags found:

$ > git tag
$ > release_1

The team now wants to make a separate branch of the tagged code so that they can fix the bug. Naming conventions is totally up to your team, but the more descriptive on what is going on the better.

$ > git checkout -b from-release_3 release_3

What this does is creates a new branch ( -b ) from the tagged branch ( release3 ) and renames the branch ( from-release3 ) and checks it out. The team would then proceed like normal doing their typical workflow of development, adding, commit, etc.

Once they are certain the bug is fixed, they then merge the branch back into the current master, push to the remote and tag the new release:

$ > git tag release_3.1 master
$ > git branch -D from-release_3

The second option is to delete the bug branch as it typically is not needed. You can also delete the first tag, but I recommend to keep it around until you know for certain your code works properly.

Remote tagging

As mentioned above, this strategy dealt around tagging local branches. In order for your entire team to have access to the tag, the tag must reside also on the remote. To make sure your local tag goes to the remote, you need to push its reference:

$ > git push origin :tag_name
$ > git push origin --tags # only use this if you want all local tags on the remote

Deleting a remote tag is simple too; just delete the tag from your local repository:

$ > git tag -d tag_name
$ > git push origin :refs/tags/tag_name # --tags will not delete tags on the remote

Keep your code (and team) sane

I know when emergency code fixes happen, things get pretty hectic. Luckily with the right tools in Git, hopefully they will become less. I am sure there are other strategies when it comes to releasing code, but this method is very straight forward and has helped out the Real Travel team a few times.

filed in: Geekery | permalink

0 shared their opinion. ADD YOURS »

Add your opinion here

Commenting is not available in this weblog entry.
March 2017
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
top of page

where you can find me

RailsConf 2010

Flickr Github Working with Rails Linked In

my twitter tweets

follow me