Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Same tag name for multiple branches

I'm currently trying to tag a git projects which same version tag for a release. The project is an extension for an exist product. For backward compatibility with the existing product, we needed to created two different versions of our project. So we created two branches named master (latest version of product) and productX.X (backward compatibility to product version X.X) which contain the different version releases of our product. We're merging the code from the branch master to the branch productX.X to keep the code in sync.

The number of branches will grow as we need to great a new version of our project when a new version of the product will be released.

Now, I want to release version 1.0.0 of our project for both product versions (latest and X.X). I read that I can use only once tag name for all branches. Is really not possible to tag different branches with the same tag "1.0.0"?

If it isn't possible what would be the good approach?

Alternative approach: Tag the branch "productversionX.X" with a postfix: master: 1.0.0 productversionX.X: 1.0.0-productX.X

I'm currently using Tower as git client and gitlab as git server.

Thanks Patrick

like image 843
Patrick Avatar asked Oct 30 '14 13:10

Patrick


People also ask

Can a tag have the same name as a branch?

You should never name a tag and a branch the same name! It makes sense in a case like this to use naming conventions on the tags to keep from colliding on the branch names. Versus when we releasing code from the master branch. You can find the common parent in git using merge-base to do a Tag on code from the past.

Are tags tied to branches?

It is important to understand that tags have no direct relationship with branches - they only ever identify a commit. That commit can be pointed to from any number of branches - i.e., it can be part of the history of any number of branches - including none.

Does git tag apply to all branches?

Yes! The difference between a branch name and a tag name is that a branch name is expected to move, and git will move it automatically in that "on a branch" case.

Can a commit have multiple tags?

We occasionally have two tags on the same commit. When we use git describe for that commit, git describe always returns the first tag. My reading of the git-describe man page seems to indicate that the second tag should be returned (which makes more sense).


2 Answers

A Git tag points to exactly one commit, i.e. there's no such thing as per-branch tags. If you have different variants of the same base version (for example 1.0.0), using a special prefix or suffix as you suggested is a reasonable solution.

Depending on what type of differences there are between the branches it may make more sense to use static or dynamic configuration in the code to select between different behaviors. That would allow you to produce all variants of the product from a single commit and hence use the same tag for them all.

like image 191
Magnus Bäck Avatar answered Sep 19 '22 17:09

Magnus Bäck


You can't.

tags are just nice names for the ugly git hashes. So a tag to a <commit-id>.

like image 30
user2959760 Avatar answered Sep 21 '22 17:09

user2959760