JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM > Git >

Creating a branch from a tag in Git

Author:JIYIK Last Updated:2025/04/04 Views:

This article introduces how we can create a new branch based on a tag in Git. If you are a regular Git user, you must know the purpose of Git tags.

These tags are just pointers to meaningful Git commits. The question is: how do you create a branch based on a Git tag?


Creating a branch from a tag in Git

If we run git logthe command, we can see the commits with tags. Here is our commit history:

Submission History

Suppose we want to create a new branch based on tag v1.o.5 at the Release v1.0.5 - Bump Codebase Version commit. How would we go about this?

This is pretty simple. We'll use the git branch command as follows:

$ git checkout -b Tag-Branch v1.0.5

This command will create a new branch called Tag-Branch and bring all commits to tag, including the commit at tag. Let's check if this is the case.

New branch

We can see that Git has created a new branch. Creating the branch deletes the commit after our tag.

Alternatively, we can choose to reset HEAD to the tag and create a new branch based on head. This is not a clean approach as you will remove commits from your branch.

You can run the following command:

$ git reset --hard <tag>
$ git checkout -b newbranch

In summary , Git allows us to create new local branches based on any tag in the repository. Using git reset --hardthe option is not always the best choice.

git branch -b new-branch <tag>A cleaner way to create branches based on tags.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Switch remote Git branch

Publish Date:2025/04/04 Views:182 Category:Git

This article will show you how to switch remote Git branches using checkout the command. The version control tool that allows you to support and manage variable versions of your application in a team of members is the Git version control to

Git shows remote tracking branches

Publish Date:2025/04/03 Views:126 Category:Git

Branches on remote Git repositories are called remote branches. These are pointers to our remote repositories, including branches, tags, etc. Local branches only exist on each developer's local personal computer, but there is only one remot

View merged and unmerged branches in Git

Publish Date:2025/04/03 Views:97 Category:Git

This article discusses how to list merged and unmerged branches in Git. Git branches encourage convergent evolution of code. This is where we create a branch as a temporary space to work on a feature, and then merge the branch with its orig

The difference between Fork and Branch on GitHub

Publish Date:2025/04/03 Views:157 Category:Git

This article discusses the difference between Form and Branch on GitHub. In the context of coding, the current era relies more on collaboration. GitHub is one of the most commonly used collaboration tools. Forking and branching on GitHub ar

How to determine the current branch in Git

Publish Date:2025/04/03 Views:165 Category:Git

Git is a unique and popular version control system that is used by most of the software developers to keep an eye on the changes made in various applications and stay connected with other teams on the running projects. It helps large teams

Difference between Git Merge Origin/Master and Git Pull

Publish Date:2025/04/03 Views:196 Category:Git

This article outlines the differences between the git merge origin/master and git pull commands. These two commands integrate changes from a remote repository into the current local branch. However, each command's operation is unique and ha

Git Pull Origin branch overwrites Master branch

Publish Date:2025/04/03 Views:144 Category:Git

This article explains how we can revert the changes made to the master git pull origin branch branch after running the command . Assume that you have a master branch and a feature branch in your local and remote repositories . You pull chan

Git Pull and Merge Commands

Publish Date:2025/04/03 Views:56 Category:Git

In the vast world of version control systems, Git is the only fast, well-organized, in-demand, and easily accessible version control system that enables users to work on various projects simultaneously in an efficient manner without any col

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial