Tags on Git

Tags of SVN are just copies of trunk. Tags of Git, on the other hand, are much more powerful. Here I’ll show you how to add/delete git tags locally and remotely.

I’ll take google_map_example for example. The google_map_example is an open project on github that shows sample codes from the book Beginning Google Maps Applications with Rails and Ajax: From Novice to Professional. The codes will be changed slightly to use Rails 2.1.

Say I’ve keyed in the codes from chapter 1, now I’d like to tag the last commit. This is can be done in this way:

phantom:~/codex/maps (master) james$ git tag -a -m "tagged chap_1" chap_1
phantom:~/codex/maps (master) james$ git tag -l
chap_1

A local tag named “chap_1” has been created. Keep in mind it’s merely a LOCAL tag, which means you have to push it to the remote repository to let other guys see it.

Here’s the tricky thing, git push won’t push the tag to the remote, git push –all won’t neither! Use this instead:

phantom:~/codex/maps (master) james$ git push --tags
updating 'refs/tags/chap_1'
  from 0000000000000000000000000000000000000000
  to   63db0052a27914db5f1a9fe6e1321309e8111f82
Generating pack...
Done counting 1 objects.
Deltifying 1 objects...
 100% (1/1) done
Writing 1 objects...
 100% (1/1) done
Total 1 (delta 0), reused 0 (delta 0)

Let’s go to the github project page to check if the tag has been pushed. Visit http://github.com/ashchan/google_maps_example/tree/master, hover mouse to “all tags”. Cheers, it’s there!

Git tag

Later I decide to remove this tag. Piece of cake, just use the git tag -d command:

phantom:~/codex/maps (master) james$ git tag -d chap_1
Deleted tag 'chap_1'
phantom:~/codex/maps (master) james$ git tag -l

Note when I use git tag -l it shows no local tags.

It’s a little bit complicated to use the push command to remove the remote tag:

phantom:~/codex/maps (master) james$ git push origin :refs/tags/chap_1
deleting 'refs/tags/chap_1'
Everything up-to-date

I googled a lot and couldn’t find any documents showing this example. Almost all people know that git push remotename :refs/heads/branchname would delete a remote branch, so it’s not very hard for me to figure out how to delete a remote tag :p

I’m new to git but I’ve been planning to migrate most projects to git. Hope this helps.