Apr 24, 2013

Git tag and versioning your project

We use tags to version our project. I will set up here basic commands we use on everyday basis and may use to handle some issues.

Showing your tags

Listing the available tags in Git is straightforward. Just type git tag.
$ git tag

Adding tags

To add tags you may do git tag tagname. But better to specify args to be able to use in scripts:
$ git tag -a 1.1.1 -m "major improvements"
$ git tag

Here we have added a tag version 1.1.1 with commit message "major improvements".

Uploading to repository

I assume you have a GitHub repo. So to push your tags there run git push (for your tagged commits commits) and then push your tags:

$ git push
Counting objects: 120, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (59/59), done.
Writing objects: 100% (69/69), 390.70 KiB, done.
Total 69 (delta 41), reused 0 (delta 0)
To ****************.git
   ******..******  master -> master
$ git push --tags
Counting objects: 1, done.
Writing objects: 100% (1/1), 157 bytes, done.
Total 1 (delta 0), reused 0 (delta 0)
To ****************.git
 * [new tag]         1.1.1 -> major improvements

You may now check this is pushed by clicking your GitHub repo's Tags button.

Removing a Tag

In case you have pushed a wrong tag... For example, if you have created a tag called push in a Git repository you would remove it from your repository by doing the following:
git tag -d push
git push origin :refs/tags/push

Now it's up to you to handle it in a release/deployment/staging/whatever script. Hope it helps. Besides, this should handle 99% of your tasks with tags. If not feel free to use official docs ;)
Comments and suggestions are welcome.

No comments:

Post a Comment