25

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 ;)

Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
egervari
  • 22,372
  • 32
  • 121
  • 175
  • 4
    Duplicate of [What is the difference between a tag and a branch in git?](http://stackoverflow.com/questions/1457103/what-is-the-difference-between-a-tag-and-a-branch-in-git) Why not do a search before asking? – Carl Norum Oct 25 '10 at 18:16
  • The dictionary meaning of branch and tag is clear enough to tell the difference of the two terms in git. Branch emphasizes the difference or different design or even different interfaces of the software. Tag is just a mile stone on a single line. – Kemin Zhou Aug 10 '18 at 18:22

4 Answers4

19

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.
Jimmy
  • 35,686
  • 13
  • 80
  • 98
  • 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. – ffxsam Mar 01 '19 at 17:39
  • @ffxsam I believe Jimmy is trying to say the same as this, from [the gitglossary man page](https://book.git-scm.com/docs/gitglossary): ```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.``` – aggregate1166877 Jul 06 '21 at 02:52
  • @ffxsam is right in general: adding a commit does not necessarily move any branches. @jimmy is right in the usual case: when a developer has a branch checked-out, and issues the `git commit` command, Git moves that branch to point to the new commit. – Keith Russell Jul 25 '22 at 15:05
  • @KeithRussell I love those rare moments where everyone is right. ;) Thanks! – ffxsam Jul 25 '22 at 21:39
11

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.

Community
  • 1
  • 1
Roberto Aloi
  • 30,570
  • 21
  • 75
  • 112
  • 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. – egervari Oct 25 '10 at 18:16
1

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.

Vladimir Georgiev
  • 601
  • 1
  • 10
  • 17
  • 5
    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. – Tom Swirly Oct 31 '16 at 16:58
-3

Tags are a fundamental building block in git; branches aren't. Git performs checks to make sure tags remain constant, never change, once created pointing at a commit. A branch on the other hand is a mere reference or pointer to a commit, and it can be updated to point at a different commit freely.

wilhelmtell
  • 57,473
  • 20
  • 96
  • 131
  • 11
    "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 Oct 31 '16 at 16:56