5 Minute Guide to Git Tags
Your busy. You’ve got stuff to do. Here’s Git tags in 5 minutes.
Creating a tag
There are two types of tag: lightweight and annotated, but use the annotated as they are a full object in the commit history.
1 | $ git tag v1.0 -a -m "1.0 Release" |
Note: All these examples will be using a tag named v1.0
, but of course, you can use any label you like.
Now that we have done that, it will leave a tag in your commit history, which you can view by typing either:
1 | $ git tag |
or
1 | $ git log --pretty=oneline |
Above, you can see that I also had to make at least one commit into my empty git repository to demonstrate this. You can only tag something if something is there!
Tags Must Be Pushed to GitHub
A tag won’t join the rest of the commits when you push to GitHub so you need to do it manually.
You can do this tag by tag, like this:
1 | $ git push origin v1.0 |
or as a group of all un-pushed tags:
1 | $ git push origin --tags |
Deleting a Tag
To remove a tag, you can use the -d
flag.
1 | $ git tag -d v1.0 |
To remove it from the remote repository (GitHub) too, try this:
1 | $ git push origin --delete v1.0 |
Oops. Tagged Wrong Place
You’ve just tagged your release but forgot to include a file…or a change…or something else. No problem: you can move them.
One option is to delete the tag and re-add it, but here’s another.
Let’s see the commits I have so far:
1 | $ git log --pretty=oneline |
We want to move our v1.0
tag to match where HEAD, or the last commit, is.
1 | $ git tag -f v1.0 3695666a5d1668b8d94bd6c45e2f861ca84add09 |
You can see in my example that I used the full commit ID but I think it need only be unique enough, so you don’t have to specify the whole string.
Hope that helps!
Hi! Did you find this useful or interesting? I have an email list coming soon, but in the meantime, if you ready anything you fancy chatting about, I would love to hear from you. You can contact me here or at stephen ‘at’ logicalmoon.com