What is the difference between a branch and a tag?

39

No git , what is the difference between branch and tag ?

    
asked by anonymous 13.08.2015 / 16:48

5 answers

34

tag is just a brand in general, in a branch specific situation that marks a situation at any given time.

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

tag usually marks a release , a version or something. So the tag is just a pointer to a specific commit whereas a branch is a path, a development branch.

tag is just a name given to a state of development. This way it is easy to access that status whenever it is needed.

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

If you work on development always over branches through commits . It is in it that the merge of the previous state is made with what has been developed now. The branch is getting developmental evolutions. You are encouraged to make a new branch , whenever possible, when you will start a new line of development.

    
13.08.2015 / 16:55
21

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

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

The tag is usually used to mark 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 is also a pointer to a node but, unlike the tag, the branch can generate a branch within this graph.

View the graph . master is a branch, just like minha-branch is. There is also a v1.2.1 tag created, pointing to the N03 node:

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

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

As you can see, within Git, they are the same but treated differently:

  • Just as you can not have a branch with the same name as a tag.
  • So different that you can not commit to a tag (unless you create a branch from this tag!), but you can commit to a branch.
13.08.2015 / 18:00
12

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 stable versions, these versions should not be changed.

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

Finishing

Branch is responsible for receiving commits during the development sprint with each new implementation, it is advisable to generate new branches as development evolves. When the project is already mature and stable, a new release is generated that will be stored in the% repository%     

13.08.2015 / 17:05
4

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

Light-weight tags

As already mentioned, they are symbolic links, they only point to a commit.

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

Annotated tags

In short, they are tags with a bit 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

    
11.08.2016 / 04:16
2

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

A tag is used to define a new version of the product. For example a system that was in development and has finished version 1.0. Then you create a tag saying that it was launched from there.

    
10.08.2016 / 11:37