what is the difference between tag and branch with git?

28,893

Solution 1

Both branches and tags are essentially pointers to commits. The big difference is that the commit a branch points to changes as you add new commits, and a tag is frozen to a particular commit to mark a point in time as having a certain significance. From one of my favorite Git resources, Pro Git:

Like most VCSs, Git has the ability to tag specific points in history as being important. Generally, people use this functionality to mark release points (v1.0, and so on). In this section, you’ll learn how to list the available tags, how to create new tags, and what the different types of tags are.

A branch in Git is simply a lightweight movable pointer to one of these commits.

Solution 2

A tag represents a version of a particular branch at a moment in time. A branch represents a separate thread of development that may run concurrently with other development efforts on the same code base.

SOURCE: This duplicate question.

What you want is probably a TAG.

Solution 3

Let's say you have - Super Awesome Product v1.0 that is stable and commited in a git repository.

You make bug fixes and changes in the branch that is v1.0 and you tag them with stuff like:

  • this fixes work item 1341 - bug ...

  • this version fixes item 234324 - bug ...

  • final v1.0

The above are all tags that represent the state of the code ( a LABEL ) when the commit was made. So, when you make v1.5 and a bug comes in for v 1.0, you take the tag final v1.0 and test the bug on it.

NOW! You decide to change the underlying Data Access of Super Awesome product. What do you do? You branch v1.0 and make a new branch called Super Awesome Product NEW DAL branch.

Tags are for snapshots of daily to daily commits. Branches are for more grand scale changes.

Share:
28,893
egervari
Author by

egervari

Updated on July 21, 2021

Comments

  • egervari
    egervari almost 3 years

    Possible Duplicate:
    What is the difference between a tag and a branch in git?

    What I'd like to do is create checkpoints for different versions of my code. So once I make a bunch of commits, I want to say, "Okay, at this point in the code, this is version 0.1 completed". And then I can make a bunch more commits and do it again and say, "Okay, this point is 0.2 completed".

    I know how to make a branch and a tag... I just don't understand the difference, and which one will do what I want ;)

  • egervari
    egervari over 13 years
    Thanks, that works nicely. It is confusing because when I go to github, I see a lot of branches with version numbers... so I was getting confused.
  • Tom Swirly
    Tom Swirly over 7 years
    "Tags are a fundamental building block in git; branches aren't." There's no meaning of "fundamental" for which that statement is correct. In particular, it's impossible to do useful work in git without branches, but there are many simple git projects out there with no tags at all.
  • Tom Swirly
    Tom Swirly over 7 years
    Looking through random projects on github seems to show the reverse - that developers use branches on a day-to-day basis and only use tags to indicate releases or other special points. I don't have a particularly unusual workflow, but I create new git branches every day, and yet months have gone by since I created a new tag.
  • ffxsam
    ffxsam about 5 years
    I don't see how this statement is accurate: "the commit a branch points to changes as you add new commits." That's not true. Adding new commits does nothing to the branch or where it points to, it's tied to a specific commit, just like a tag.
  • aggregate1166877
    aggregate1166877 almost 3 years
    @ffxsam I believe Jimmy is trying to say the same as this, from the gitglossary man page: The most recent commit on a branch is referred to as the tip of that branch. The tip of the branch is referenced by a branch head, which moves forward as additional development is done on the branch. A single git repository can track an arbitrary number of branches, but your working tree is associated with just one of them (the "current" or "checked out" branch), and HEAD points to that branch.