How to create a Git branch from a tag

Greg Foster
Greg Foster
Graphite software engineer

Creating a branch from a tag in Git is a useful operation when you need to start a new line of development from a specific point in the repository's history. Tags in Git are often used to mark release points (v1.0, v2.0, etc.), and sometimes there's a need to patch an older version or use a tag as a base for a new feature. This guide will walk you through the process of creating a branch from a tag, both locally and from a remote tag.

Before exploring the commands, it's important to understand what tags and branches are:

  • Tag: A tag in Git is a pointer to a specific commit, generally used to mark specific points in the repository's history, such as releases.
  • Branch: A branch in Git is also a pointer, but it moves forward as new commits are made, making a branch a collection of commits. Branches are used for developing features, fixing bugs, and generally diverging from the main line of development.

Before creating a new branch from a tag, especially a remote tag, you should update your local repository with all the tags from the remote repository.

Terminal
git fetch --all --tags

This command fetches all branches and tags from the remote, ensuring your repository is up to date.

To view the list of tags in your repository, use:

Terminal
git tag

This will list all the tags in your repository, helping you decide from which tag you want to create a new branch.

If you have already fetched the tags from the remote or you are working with a local tag, you can create a new branch from it using the following command:

Terminal
git checkout -b new-branch-name tag-name

Replace new-branch-name with the desired name for your new branch, and tag-name with the name of the tag you want to branch from.

If you want to create a branch directly from a remote tag (especially if the tag isn't present locally), you can do so by specifying the full tag reference:

Terminal
git checkout -b new-branch-name origin/tags/tag-name

Again, replace new-branch-name with your branch name and tag-name with the remote tag name.

When you create a new branch locally in Git, it exists only on your local machine until you explicitly push it to a remote repository. Once you've pushed the branch to the remote repository, it becomes available to others who have access to that repository. Additionally, when you push a branch to a remote repository for the first time, Git automatically sets up a remote-tracking branch associated with that branch on the remote repository.

A remote-tracking branch is a local reference in your repository that keeps track of the state of a branch on a remote repository. It allows Git to know which commits have been added to the remote branch since the last time you fetched from or pushed to the remote repository.

To push your branch, run:

Terminal
git push origin new-branch-name

This command pushes the new branch to the remote repository (assuming 'origin' is your remote name).

  • Naming branches: Choose names that clearly indicate the purpose of the branch, especially if branching from a tag for fixes or specific features.
  • Keep your branches synced: If you continue development on this new branch, regularly pull changes from the main branch (if applicable) to keep it updated.
  • Tagging new releases: If your branch from a tag leads to significant changes or fixes, consider tagging the end of this branch as a new release.

For further reading on branching see the official Git documentation.

Stay unblocked. Ship faster.
Experience the new developer workflow - create, review, and merge code continuously. Get started with one command.
Get started

Give your PR workflow
an upgrade today

Stack easier | Ship smaller | Review quicker

Or install our CLI.
Product Screenshot 1
Product Screenshot 2