DEV Community

Jyotishman Saikia
Jyotishman Saikia

Posted on

Git tags: what are they? How do tags and branches differ from one another?

Tags vs Branch

Let's discuss this one by one with an example.

I hope you are already familiar with git branch. For those who are new to git branch its a way to work multiple features and keep your code separated by branches.

Example: You can work on two different features at the same time by creating two branch. Code from both the branch won't interfere with each other. Let's suppose master is the stable branch where all the production code is there, from there you can create different branch according to your dev requirement.

Creating git branches

If there are multiple developers working on the same project on multiple features, you need to merge the code to a common branch (master) for deployment.

After deploying the master branch what if there is an issue with any of the developer's branch?

What should we do in this case since its breaking our production app?

Quickest solution would be to revert the merge commit that has the issue.

But there is an even smartest way to solve things when things go wrong on production.

Git tags

This is where git tags come in. Git tags allow us to indicate certain points in a repository's history.
We can create tags at any time and reference to a commit.
But my suggestion would be to create a tag whenever there is commit made to master branch.

Example: Create a tag everytime a developer feature branch is merged into master.

Git tags

This way if there is any issue in any of the merge commits then we can simple go back to 2nd stable tag instead of the first tag.

To create a tag locally-

git tag tag-v.0.0.1

To push the tag-

git push origin tag-v.0.0.1

This is a manual way of creating a tag and push it. But we can automate this thing by using github actions.

So whenever there is any push commit to master , pick the latest tag and increment it by one.

If my last tag is tag-v.0.0.1 it will automatically increment and create tag tag-v.0.0.2.

If you want to know how to create this auto tag on master comment down below. If you like this post do give a comment.

Top comments (0)