A brand new repository has only one of those (called master
main
), which automatically moves to the latest page (think commit) you've written. However, you're free to create and use more bookmarks, in order to mark other points of interest in the book, so you can return to them quickly.
Also, you can always move a particular bookmark to some other page of the book (using git-reset
, for instance); points of interest typically vary over time.
You can think of tags as chapter headings.
It may contain a title (think annotated tags) or not. A tag is similar but different to a branch, in that it marks a point of historical interest in the book. To maintain its historical aspect, once you've shared a tag (i.e. pushed it to a shared remote), you're not supposed to move it to some other place in the book.
What you need to realize, coming from CVS, is that you no longer create directories when setting up a branch.
No more "sticky tag" (which can be applied to just one file), or "branch tag".
Branch and tags are two different objects in Git, and they always apply to the all repo.
You would no longer (with SVN this time) have to explicitly structure your repository with:
branchesmyFirstBranchmyProjectmySubDirsmySecondBranch...tagsmyFirstTagmyProjectmySubDirsmySecondTag...
That structure comes from the fact CVS is a revision system and not a version system (see Source control vs. Revision Control?).
That means branches are emulated through tags for CVS, directory copies for SVN.
Your question makes senses if you are used to checkout a tag, and start working in it.
Which you shouldn't ;)
A tag is supposed to represent an immutable content, used only to access it with the guarantee to get the same content every time.
In Git, the history of revisions is a series of commits, forming a graph.
A branch is one path of that graph
x--x--x--x--x # one branch\ --y----y # another branch1.1^|# a tag pointing to a commit
See Jakub Narębski's answer for all the technicalities, but frankly, at this point, you do not need (yet) all the details ;)
The main point is: a tag being a simple pointer to a commit, you will never be able to modify its content. You need a branch.
In your case, each developer working on a specific feature:
Instead of tracking directly the branches of your colleagues, you could track only the branch of one "official" central repository to which everyone pushes his/her work in order to integrate and share everyone's work for this particular feature.
Branches are made of wood and grow from the trunk of the tree. Tags are made of paper (derivative of wood) and hang like Christmas Ornaments from various places in the tree.
Your project is the tree, and your feature that will be added to the project will grow on a branch. The answer is branch.
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.
It looks like the best way to explain is that tags act as read only branches. You can use a branch as a tag, but you may inadvertently update it with new commits. Tags are guaranteed to point to the same commit as long as they exist.
Tags can be either signed or unsigned; branches are never signed.
Signed tags can never move because they are cryptographically bound (with a signature) to a particular commit. Unsigned tags are not bound and it is possible to move them (but moving tags is not a normal use case).
Branches can not only move to a different commit but are expected to do so. You should use a branch for your local development project. It doesn't quite make sense to commit work to a Git repository "on a tag".
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.
The Git Parable explains how a typical DVCS gets created and why their creators did what they did. Also, you might want to take a look at Git for Computer Scientist; it explains what each type of object in Git does, including branches and tags.
A tag is used to mark a version, more specifically it references a point in time on a branch. A branch is typically used to add features to a project.
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 fixlightweight tags
for the test
environment on feature branchesannotated 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).
neovim on github:
v0.3 is a branch
v0.3.1 ... v0.3.4 ... are tags
nightly and stable are tags, not branches