添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
  • Colocation
    Overview
  • Data Center as a Service
    Solutions for Digital Transformation
  • Hardware as a Service
    Flexible Hardware Leasing
  • Meet-Me Room
    The Interconnectivity Hub
  • Schedule a Tour
    Guided Virtual Data Center Tour
  • Data Center Locations
    Global Data Center Footprint
  • Platform
    Overview
  • Rancher Deployment
    One-Click Kubernetes Deployment
  • Intel Xeon E-2300
    Entry-Level Servers
  • 4th Gen Intel Xeon Scalable CPUs
    Boost Data-Intensive Workloads
  • Alliances
    Technology Partnerships
  • Object Storage
    S3-Compatible Storage Solution
  • Dedicated Servers
    Overview
  • FlexServers
    Vertical CPU Scaling
  • Intel Xeon-E Servers
    Intel Xeon 2200 Microarchitecture
  • GPU Servers
    Servers with NVIDIA Tesla GPUs
  • Dedicated Servers vs. BMC
    Compare Popular Platforms
  • Promotions
    See Available Discounts
  • Buy Now
    See All Servers
  • Managed Private Cloud (MPC)
    Highly Customizable Cloud
  • Data Security Cloud
    Secure-By-Design Cloud
  • Hybrid Cloud
    Multi-Platform Environment
  • Edge Computing
    Globally Distributed Servers
  • Object Storage
    S3 API Compatible Storage Service
  • Bare Metal Cloud
    API-Driven Dedicated Servers
  • Alternative Cloud Provider
    Overcome Public Cloud Limitations
  • Backup Solutions
    Veeam-Powered Services
  • Disaster Recovery
    VMware, Veeam, Zerto
  • Veeam Cloud Connect
    Backup and Replication
  • Managed Backup for Microsoft 365
    Veeam-Powered Service
  • Data Security Cloud
    Secure-by-Design Cloud
  • Encryption Management Platform (EMP)
    Cryptographic Key Management
  • Confidential Computing
    Data-in-Use Encryption
  • Ransomware Protection
    Data Protection and Availability
  • DDoS Protection
    Network Security Features
  • Network Overview
    Global Network Footprint
  • Network Locations
    U.S., Europe, APAC, LATAM
  • Speed Test
    Download Speed Test
  • Blog
    IT Tips and Tricks
  • Glossary
    IT Terms and Definitions
  • Resource Library
    Knowledge Resources
  • Events
    Let's Meet!
  • Newsroom
    Media Library
  • Developers
    Development Resources Portal
  • APIs
    Access Our Public APIs
  • GitHub
    Public Code Repositories
  • Git Checkout Tag

    December 2, 2021

    Introduction

    G it tags help developers create source points during development. The primary purpose is to mark and reference release versions. Checkout works with any Git object, including tags.

    This tutorial will show you how to check out a Git tag correctly.

    Prerequisites

    • Git installed and configured.
    • A cloned Git remote or a locally set up project.
    • Access to the command line/terminal.

    Note: Need to install Git? We have guides available for the following OSes:

  • Ubuntu 18.04/20.04
  • CentOS 8
  • MacOS
  • Windows
  • Git Checkout Tag

    To find the tag name and checkout a Git tag, follow the steps below:

    1. List the fetched tag names from a remote repository with:

    git tag

    Alternatively, search the tag names by a specified pattern:

    git tag -l "<pattern>"

    For example:

    git tag -l "v2.*"

    Proceed to the final step once you've found the tag name you'd like to checkout.

    2. Checkout the tag with:

    git checkout <tag name>

    For example:

    git checkout v2.1

    The command makes the repository go into Detached HEAD state .

    The state allows viewing, making changes, and committing. However, no specific branch is tracking these changes. To confirm this, run the following command:

    git branch

    The output shows the commits currently associated with a specific revision instead of a branch.

    Checkout Git Tag as a Branch

    To checkout a Git tag as a branch, create a new branch and add a tag name:

    git checkout -b <new branch name> <tag name>

    For example, to check out a v2.1 tag to a version2.1 branch, use:

    git checkout -b version2.1 v2.1

    The output confirms the branch switch.

    Print the logs to the console to verify the code starts from the tag:

    git log --oneline --graph

    Press q to exit the log. To push the changes from the local branch, set an upstream branch and push the code.

    Note: Learn how to rename Git tags .

    How to Checkout the Latest Git Tag

    Follow the steps below to check out the latest Git tag:

    1. Fetch the latest tags from the repository:

    git fetch --tags

    The command retrieved one new tag from the remote repository.

    2. Use the git describe command to fetch the latest tag with commits and save the information into the $tag shell variable:

    tag=$(git describe --tags `git rev-list --tags --max-count=1`)

    Use the echo command to show the tag name. The variable stores the tag with the latest commit from all branches.

    3. Lastly, checkout the tag to a new branch with:

    git checkout $tag -b latest

    The branch latest now tracks the changes made starting from the latest tag.

    Conclusion

    After this tutorial, you know how to check out a Git tag in a detached head state and a new branch. The tags help track release version information.

    Next, grab our Git commands cheat sheet PDF with commonly used Git commands.

    Was this article helpful?
    Yes No
    Milica Dancuk
    Milica Dancuk is a technical writer at phoenixNAP with a passion for programming. With a background in Electrical Engineering and Computing, coupled with her teaching experience, she excels at simplifying complex technical concepts in her writing.
    Next you should read
    DevOps and Development SysAdmin What Is Git Bash; Working with Git Bash Commands
    September 8, 2021
    Git Bash lets you manage your code and repository using...
    Read more DevOps and Development SysAdmin How to Use Git {Beginner's Guide}
    September 2, 2021
    Git is the most popular version control system in the world. Learn to use...
    Read more DevOps and Development SysAdmin What Is Git?
    July 28, 2021
    This article helps you understand what git is, guides you through its features, use cases, and the way git works.
    Read more DevOps and Development SysAdmin How to Remove a Git Remote From Repository
    November 17, 2020
    When a remote repository moves to another host or a...
    Read more