Using Versions in Git

You really appreciate versioning when several people come up to you all at once with different bugs from different iterations of your code and you don’t have a versioning system in place. A first step in that process is using Git tags. (There’s more than one way to implement versions, but this is one way.)

Add a Tag

There’s different opinions on the best way to do versions, but one common way is to say RELEASE.FEATURE.BUG. So v2.3.150 would be the second version of something, after they’ve added three new features and fixed one hundred and fifty bugs. Since you can’t foresee how many bugs you will introduce, you don’t have to left-pad you bugs digit with zeros, you can just go from *.*.9 to *.*.10.

Doing this in Git we would say,

$ git tag -a v1.0.0 -m "This is my first release!"
$ git push origin v1.0.0

Here, “-a” stands for add I guess, and “-m” stands for message. If you want to push all of your tags at once, you can use,

$ git push origin --tags

Remove a Tag

This is easy, but it requires two steps: an obvious one, and a not so obvious one,

$ git tag -d v1.0.0
$ git push origin :refs/tags/v1.0.0

Here is the official Git documentation on tagging.