Developer. Leader. Speaker. Doer of Things. Bookworm. Mostly Harmless.
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:
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.
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.
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.
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.
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!
Also published at https://medium.com/@vogeleah/tags-vs-branches-in-git-16c4a3dc0a1f
Create your free account to unlock your custom reading experience.