Git
Version Control
Branching
Software Development
Git Tags

How to create a new branch from a tag?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Creating a branch from a tag in Git is straightforward once you remember what a tag actually is: a reference to a specific commit. A branch is just another reference, but unlike a tag, it is meant to move forward as you add commits. So creating a branch from a tag really means creating a movable reference that starts at the tag's commit.

The Basic Command

If the tag already exists locally, create the branch directly from it.

bash
git switch -c hotfix/v1.2.3 v1.2.3

Older Git versions can use:

bash
git checkout -b hotfix/v1.2.3 v1.2.3

Both commands create a new branch named hotfix/v1.2.3 and point it at the commit referenced by tag v1.2.3.

Fetch Tags First if Needed

If the tag exists only on the remote, fetch tags before creating the branch.

bash
git fetch --tags
git switch -c hotfix/v1.2.3 v1.2.3

You can inspect available tags with:

bash
git tag --list

This avoids the common mistake of assuming the tag is present locally when it is not.

Why This Works

A tag identifies a fixed commit. Git does not care whether a new branch starts from a commit reached by a branch, by a tag, or by a raw commit hash.

That means these are conceptually similar:

bash
git switch -c feature-x main
git switch -c hotfix/v1.2.3 v1.2.3
git switch -c test-branch a1b2c3d

In each case Git resolves the reference to a commit and creates a new branch starting there.

Use Cases for Branching From a Tag

This is common when you need to:

  • create a hotfix from a released version
  • backport a bug fix to an old release line
  • investigate behavior from a specific shipped snapshot
  • start maintenance work from a stable milestone

A tag is often the cleanest base for this because it points to the exact release commit rather than whatever main looks like today.

Push the New Branch to the Remote

Creating the branch locally is only the first step. If teammates or CI need it, push it.

bash
git push -u origin hotfix/v1.2.3

The -u flag sets the upstream so later git push and git pull commands know which remote branch to use.

Annotated and Lightweight Tags Both Work

Git supports annotated tags and lightweight tags, but for branch creation that distinction usually does not matter. Both kinds of tag still resolve to a commit for this purpose.

The difference matters more for metadata, signing, and release documentation than for the actual branch-creation step.

Verify the Branch Base

If the branch is important, check that it really points where you expect.

bash
git log --oneline --decorate -n 5
git show v1.2.3 --no-patch

This is especially useful in repositories where tag names are similar or where multiple maintenance lines exist.

Do Not Commit on Detached HEAD by Accident

A common alternative workflow is checking out the tag directly.

bash
git checkout v1.2.3

That puts you in detached HEAD state. It is fine for inspection, but not ideal for ongoing development because new commits are not attached to a branch name. If you intend to make changes, create the branch explicitly.

Common Pitfalls

  • Forgetting to fetch tags before trying to branch from a remote tag.
  • Checking out the tag directly and then committing in detached HEAD state.
  • Assuming tags behave like branches and move over time.
  • Creating the branch locally but forgetting to push it to the remote.
  • Branching from the wrong similarly named tag without verifying the target commit.

Summary

  • A tag is a fixed reference to a commit.
  • Creating a branch from a tag means creating a movable branch reference at that commit.
  • Use git switch -c new-branch tag-name or git checkout -b new-branch tag-name.
  • Fetch tags first if the tag is not local.
  • If you intend to develop from a tag, create a branch instead of staying on detached HEAD.

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions