What is the difference between a "branch" and a "tag"?

Asked

Viewed 7,270 times

44

In Git, what is the difference between a branch and a tag?

  • Just leave an addendum, that we talk about a long time, many repositories, like Laravel for example, use the branchs to divide the versions because they usually continue to make updates in both branchs.

  • http://imasters.com.br/artigo/21127/software-livre/como-trabalharcom-tags-no-git?trace=1519021197&source=single here explains well the difference between the two.

5 answers

42


To tag is only a brand, in general, in a branch specific marking a situation at a given time.

The branch traditional should be something experimental, something in parallel, something that will potentially be incorporated into the main development, to branch leading.

To tag usually score a release, a version or something. Then the tag is just a pointer to a commit specific while a branch is a path, a branch of development.

To tag is just a name given for a state of development. This way it is easy to access that state whenever necessary.

In Git there is no cost in having a tag, is something symbolic and does not take up space in the repository. You do not change what is in the tag. It is a static branch that can be used at any time. A tag will be used eventually, when there is some important event in the development and that there needs this mark to return to it other times. Usually this event is a release.

If you work in development always on top of branches through the commits. That’s where you do the merge of the previous state with what was developed now. The branch is receiving development evolutions. It is encouraged to make a new branch, where possible, when it will start a new development line.

Branch/tag no Git

  • Here’s something we have to learn to do here where I work (the last paragraph)

  • In the SVN That’s different, right? @bigown

  • In SVN We have Trunk that functions as the main line of the tree!

  • 1

    @Wallacemaxters Not everyone encourages the use of branches - many avoid them. I worked on projects with everyone commiting on the same branch, and worked on others where the cost of branchs integration was reduced with integrations at shorter intervals, until the integrations were completely removed (all commiting on the same line)Bringing in a lot of money. Perhaps the problems in your company are better solved in another way. Read about the practice of Continuous Integration (Continual Integration) here: http://martinfowler.com/articles/continuousIntegration.html

  • @Wallacemaxters And in this answer there is a very simple summary about using a single line of development and using branches only to build maintenance releases in stable versions: http://answall.com/a/48866/14584

22

To make the difference clear, think of the Git repository as a graph, with each node of this graph being a commit.

Tag is a pointer you use to point to any node in this graph.

The tag is usually used to mark system versions. Example: You can create a tag v1.2.1 at a certain point in your repository, continue commiting to the repository and return to this tag v1.2.1 easily.

Branch is also a pointer to a node but, unlike the tag, the branch can generate a branch within this graph.

See the graph next. The master is a branch, just like minha-branch is. There is also a tag v1.2.1 created, pointing to the knot N03:

                            |minha-branch|
                                  |
                                  |
                             .---N05
                            /
N01<---N02<---N03<---N04<--´-----N06
               |                  |
               |                  |
           |v1.2.1|           |master|

Creating a tag or a branch is as simple and fast as write 41 bytes in a file on disk.

As you can see, within Git, they’re the same, but treated in different ways:

  • So similar that you can’t have a branch with the same name as a tag.
  • So different that you can’t commit to a tag (unless you create a branch from this tag!), but you can commit to a branch on a branch.
  • 2

    +1 by drawing, rsrs

  • I think the comment about SVN does not apply...from what I know, in SVN branchs and tags are identical,and the creation cost is very low too.

  • @zentrunix, removed. At the time when I used a branch in SVN this process was very heavy, but I do not know how SVN is today, I believe it has evolved and improved.

12

Branch:

A branch of its main "tree" of development, usually created to generate corrections or new implementations, when this branch arrives at the end we can make a Merge for the main branch of your project.

Tag:

We can look at the tag with a "repository" of stable releases, these versions should not be changed.

Tag
--release 1.0
---release 1.0.1
----release 2.0
-----release 2.1 

Finalizing

The Branch is responsible for receiving the modifications(commits) during the development sprint each new implementation is recommended to generate new branches as the development evolves. When the project is already mature and stable a new release is generated that will be stored in the TAG repository

4

Just a complement to everything that has already been said, there are 2 types of tag:

Light-Weight tags

Which, as already stated, are like symbolic links, just point to a commit.

As for the space in the repository, git creates only one file with the tag name inside, so it’s minimal.

Annotated tags

Summarizing are tags with a little more information, in addition to pointing to the commit, also stores the name and email of the creator of the tag, date, and tag message, like the commit message.

Since it contains much more information than a light-Weight it ends up being stored as a full git object, it soon takes up more space than the light-Weight

2

Branch are ramifications (to the letter) of a work in parallel to what is already in production or in master. We use branchs to encode some specific functionality or to fix bugs, for example.

Already a tag we use to define a new version of the product. For example a system that was in development and was completed version 1.0. Then you create a tag saying that from there was released such version.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.