How is a tag different from a branch in Git? Which should I use, here?

Viewed 260129

I am having some difficulty understanding how to use tags versus branches in .

I just moved the current version of our code from to , and now I'm going to be working on a subset of that code for a particular feature. A few other developers will be working on this as well, but not all developers in our group are going to care about this feature. Should I be creating a branch or a tag? In what situations should I be using one versus the other?

14 Answers

I like to think of branches as where you're going, tags as where you've been.

A tag feels like a bookmark of a particular important point in the past, such as a version release.

Whereas a branch is a particular path the project is going down, and thus the branch marker advances with you. When you're done you merge/delete the branch (i.e. the marker). Of course, at that point you could choose to tag that commit.

the simple answer is:

branch: the current branch pointer moves with every commit to the repository

but

tag: the commit that a tag points doesn't change, in fact the tag is a snapshot of that commit.

simple:

Tags are expected to always point at the same version of a project, while heads are expected to advance as development progresses.

Git User Manual

We use

  • branches in the dev environment for feature development or bug fix
  • lightweight tags for the test environment on feature branches
  • annotated tags for the release/prd (main branch)

After each annotated tags, all feature branches rebase from the main branch.

As said by others, a branch is a line of development and the head moves forward as newer commits arrive. This is ideal for the feature development.

Lightweight tag is fixed to a specific commit, which makes it ideal to create an internal version and let qa team to test a feature after dev is completed.

Annotated tag is ideal for the release to production, as we can add a formal message and other annotations when merging the tested feature branch to the main branch (stable).

Release Management with Git

neovim on github:

v0.3 is a branch enter image description here

v0.3.1 ... v0.3.4 ... are tags

enter image description here

nightly and stable are tags, not branches

enter image description here

Related