Top Differences Between Tags and Branches In Git You Must Know

Written by leahvogel | Published 2021/03/25
Tech Story Tags: git | version-control | branches | git-tags | beginners | beginners-to-coding | version-control-in-git | version-control-system

TLDR The most recent commit on a branch is referred to as the tip of that branch. Branches are dynamic and code can be added to them. A tag is most typically used to mark a particular point in the commit ancestry chain. A branch is an active line of development whereas a tag is a reference to a specific commit on any 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 one of them.via the TL;DR App

New to version control? Welcome! 👋 Understanding the lingo is very important. This can be overwhelming, but don’t worry, you’ll get there!
In this short post I will explain what a branch and what a tag is, what they are used for and the differences between them.
As defined in gitglossary:
branch
A “branch” is an active line of development. 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.
tag
A ref pointing to a tag or commit object. In contrast to a head, a tag is not changed by a commit[...]. A tag is most typically used to mark a particular point in the commit ancestry chain.

Branches:

Image by Free-Photos from Pixabay
Let’s explain how this works in real life.
You write code on a branch. You may have a repository with only one branch (master), and then code you commit would be added to that branch. A more common workflow is to create (checkout) a new branch when working on a feature or a bug, stemming from a master or develop branch. When your work is completed, saved (committed) and pushed remotely, hopefully your code will be reviewed and merged into the main development branch.
When you checkout a branch, it points to the most recent commit that you have locally. Branches are dynamic and code can be added to them.

Tags:

Image by BRRT from Pixabay
A tag points to a specific commit on any branch. You cannot add more code to a tag — it is a reference to a specific commit, kind of like a snapshot.
When would you want something like this? It is useful to create tags when releasing versions. When checking out a tag you can always be sure you’ll be getting the same code each time.

In conclusion:

A branch is an active line of development whereas a tag is a an immutable reference to a specific commit on a branch.
Hope that clears up some confusion for you. Happy developing!

Written by leahvogel | Developer. Leader. Speaker. Doer of Things. Bookworm. Mostly Harmless.
Published by HackerNoon on 2021/03/25