What is the difference between a branch and a tag?

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

Author: Maniero, 2015-08-13

5 answers

A tags it's just a brand, in general, in a branch specific that marks a situation at a given time.

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

The Tag usually tags a release, a release or something. So the Tag is just a pointer to a commit specific whereas a branch is a path, a development branch.

The Tag is just a name given to a development state. This way it is easy to access that state whenever it is needed.

In Git there is no cost in having a Tag, it 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. The 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 on development always on top of branches through commits. It is in it that one does the merge of the previous state with what has been developed now. The branch is receiving development evolutions. It is encouraged to make a new branch , whenever possible, when will start a new line of development.

Branch / tag in Git

 41
Author: Maniero, 2016-08-11 11:34:20

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

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

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

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

See graph below. The master is a branch, just as minha-branch is. There is also a tag v1.2.1 created, pointing to Node N03:

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

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

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

  • so equal 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 can commit to a branch.
 22
Author: Dherik, 2018-04-27 18:13:13

Branch:

A branch of your main development "tree", usually created to generate fixes or new implementations, when that 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 releases of the stable versions, these versions should not be changed.

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

Ending

The Branch gets the responsibility to receive the changes (commits) during the development sprint with each new implementation it 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 of the{[7] repository]}

 12
Author: Wellington Avelino, 2015-08-13 16:27:17

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

Light-weight tags

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

As for 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, it also stores the name and email of the creator of the tag, date, and tag message, type the commit message.

Since it contains much more information than a light-weight it ends up being stored as a complete git object, so it takes up more space than light-weight

 4
Author: Neuber Oliveira, 2016-08-11 11:28:54

Branch are branches (literally) of a work in parallel to what is already in production or in the master. We use branchs to code 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 a tag is created saying that from there it was released to such a version.

 2
Author: , 2016-08-10 09:37:22