How to tag a release in Git

- by

Git-Logo-2ColorLike in Subversion, Git supports tags. Most developers use tags to “freeze” a bunch of files at a moment in time, much like a snapshot. Commonly this feature is used whenever a new release of your software is… well… released.

Xcode does not support this feature via the GUI, but of course Git does. Let’s see how to do this from the command line.

Tagging the current branch

You can create a tag from whatever you’ve just committed, no matter which branch this is on. Simply head over to your project and type the following:

git tag -a v1.1 -m 'Version 1.1'

This will create a tag called “v1.1″ with the comment “Version 1.1″. To see a list of all your tags, type

git tag

Tagging a previous commit

If you’ve forgotten to create a tag from an earlier commit you can do that too. Simply specify part of that ugly long hash Git creates with every commit. They’re not easy to remember of course, so let’s list each commit to find the one you need:

git log --pretty=oneline

bd75bbfcee6de546c5c0dbb62387241b534481c8 added Season 1
a646c0bfd8c84087b6a37b77352761d84a6d57af added pictures
e9e2732cffe5ce81eb401e78e529f946ccdac226 wish I tagged this
152996254bee69fc3caf7e5c703e7ebaabd4afd4 Initial Commit

Say you wanted to create a tag from the second commit, the one that reads “wish I tagged this”. Tag it just like above, but add the first few hash digits like so:

git tag -a v1.2 -m 'Version 1.2' e9e273

Pushing Tags to a remote

Just like branches, your tags are not automatically pushed to a remote. You must specify this explicitly. You also need to know what your remote is called. Let’s assume it’s called “Remote”, here’s how you’d push the tag we’ve just created:

git push Remote v1.2

For a more detailed explanation, check out this excellent article from Git SCM.



If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.