George
George

Reputation: 7317

Do both branches and tags both -- literally speaking -- refer to commits?

In git, tags refer to commits. So what, literally speaking, does a branch refer to?

I know that, intuitively speaking, I think of a branch as a set of related commits, but is that the correct way to think about them?

Upvotes: 1

Views: 74

Answers (4)

VonC
VonC

Reputation: 1324737

A branch refers to the tip of a commit history: all the commits accessible from that particular branch head (written in .git/refs/heads/abranch).

enter image description here

(image from Atlassian Using Branches tutorial)

This "accessibility" characteristic result from the DAG nature the commits

DAG

from Git: an introduction

DAG bis

Upvotes: 3

Phantom
Phantom

Reputation: 875

You should read the documentation, it's really helpful. Git branching, Git tagging

To answer your question. Tagging is to give some specific name to a commit, in order to make your project's history easier to understand. It's useful if you need (or want) to do a rollback to a specific version of your project.

Branch are more complete (and complex) things. When you create a new branch you "fork" your project. It's mean you can work on both branch in different ways and your commit of the branch A will not interfere in your branch B.

This can be useful in many case. For example, when you work in team, everybody as to do a part of the project, so they created a branch for each part, and then they merge everything. Or when your work for a software support, for each issue you will create a branch, and when you fixed it you merge it with the branch master. Or,...

Upvotes: 0

Dietrich Epp
Dietrich Epp

Reputation: 213358

Yes, if I understand your question correctly.

In Git, a branch and a tag are both just names which point to commits. The major difference between them is just user interface. You can browse both branches and tags in the .git/refs directory. Note that tags can also have annotations.

Upvotes: 1

MrKickkiller
MrKickkiller

Reputation: 521

A branch is a way of seperating your commits.

Generally speaking if you put commits on a seperate branch from master, you are testing experimental code, which you don't want to have on your main master branch (master is mostly stable and release code). Once your experimental code is deemed stable you can merge the branch into your master. This means that your master branch now has the previously stable code and your new previously experimental code.

Another way to use branches is if you have some modularity in your program. Eg: Input handling classes/ File Handling classes etc. If you co op on a project with this structure, one person can have his Input handling adjustments on a seperate branch, and idem dito for the file handling adjustments. This makes for cleaner commit lines. Also this means that you can work without having to have the (probably) unstable commited code from your buddy in your workspace.

Upvotes: 0

Related Questions