8

I am a bit confused about git tagging even after reading the documentation.

Say I am making changes to my develop branch.

  1. Should I create a tag before making changes, or should I add my tag after making my changes? Which workflow is better?

  2. Initially I was ask to just use git push --tags, but after running git tag I was shown a list of 5 tags (release-1, ..., release-5 ), when I tried running git tag -v release-5 I was prompted with the following errors, the same applies for other releases. Any ideas?

    error: 575bbe56b0c021c51e2b819763c1ff15cc5d2186: cannot verify a non-tag object of type commit.
    error: could not verify the tag 'release-5'
    
  3. If I have used git push to push tags in the Develop branch, followed by a merge to the Master branch, do I still need to do another round of git push --tags

  4. How are tags different from branches? And which is better?

2 Answers 2

11

Should I create a tag first before I do any changes though I know that I can tag it after the changes. Which workflow is better?

You don't have to, but it can help if you want to go back to an identified point.

You need to be aware of two kinds of tags though (as mentioned in git tag):

  • lightweight tags (reference for the SHA-1 object name of the commit object)
  • annotated tags (independent tag object, including a creation date, the tagger name and e-mail, a tagging message, and an optional GnuPG signature): git tag -a myTag or git tag -m "new myTag" myTag both created annotated tags.
    git tag myTag creates a lightweight tag only.

Annotated tags are meant for release while lightweight tags are meant for private or temporary object labels.

cannot verify a non-tag object of type commit.

You can only verify an annotated tags, since it is an independent object which can support an optional gpg signature (that is the signature you are trying to verify with the -v option).
A lightweight tag is just a shortcut to a commit.

git push --tags in the Develop branch:

That is an operation which will impact your remote upstream repo.
And it will push all tags, not just the ones set in the Develop branch.
To push only the ones that matters, I recommend git push --follow-tags

followed by a merge to the Master branch,

That is a local operation done in your local repo, and has nothing to do with the git push just done before.

do I still need to do another round of git push --tags

Both operations are completely unrelated.

How different are the tags different from branches? And which is better?

As opposed to SVN, tags are very different from branches and complement them: one isn't better than the other.

  • branches are for isolating a development effort (see "When should you branch?").
  • tags are for identifying specific points in history as being important (for instance, for marking releases).

Branches can be renamed or deleted easily.
(Annotated) Tags cannot be modified without affecting the history of the git repo.

Sign up to request clarification or add additional context in comments.

9 Comments

Thanks for your explanation. Another question just pop into my mind. Prior to the question 2 that I have mentioned, I was wondering could it be a cause where I run git push --tags even though in my previous commits etc I did not even create any tags?
@dissidia "a cause"? a cause for what? And you should use git push --follow-tags: git push --tags only work if you did a git push first, as opposed to git push --follow-tags which does both in one command: stackoverflow.com/a/17219399/6309
my bad. I was trying to say because not 'be a cause'... oops. And can I also presume that git tag will be created automatically as soon as a git push command is used, irregardless whether I have create a tag before it?
@dissidia didn't see the edit. Again: git push alone doesn't push tags (only commits and branches). git push --tags pushes them (only if git push has been done before). git push --follow-tags does both (pushes commit and tags). No tag is created automatically.
@dissidia yes, correct. Except git push --tags won't push anything at all (since it is used to push only tags), while git push --follow-tags will at least push the commits (and not the tags, if said tags weren't created first).
|
0

First of all, nice explaination by VonC. Now moving to your question,regarding the workflow for tagging,

  1. You have to tag your initial version of git repo with lightweight or annotated tag (choice is yours), usually i prefer annotated tags. {P.S: its always better to have initial version of tag. It is not must. }
  2. Then make your changes, commit and push them. And again you can simply use git tag command to create a tag and you have to push it using "git push origin --tags".
  3. Once it is done, your tagging is done with your changes. Now if you can check the diff using "git diff tag1 tag2".

I hope it will help you :)

2 Comments

This answer is incorrect, you can tag local branches, and they don't have to be merge commits. Also, it is not necessary to tag the "initial version of your repo", before making any changes, you can create a tag whenever you feel that it is appropriate to do so.
@cupcake: Agreed with your comments, it is not neccessary to have initial tag, but is's my personal suggestion to tag initial version of base code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.