Read Anthropic’s case study about Graphite Reviewer

How to create a Git branch from a tag

Greg Foster
Greg Foster
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


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.
Join 20,000+ developers at top companies
Stop wrestling with Git commands
The Graphite CLI takes all the pain out of Git, allowing you to ship faster and stop googling Git commands.
main
diff1
diff2

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).

Join 20,000+ developers at top companies
The best engineers use Graphite to simplify Git
Engineers at Vercel, Snowflake & The Browser Company are shipping faster and staying unblocked with Graphite.
main
diff1
diff2
  • 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.

Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2