How to clone from a git tag example
A git tag typically represents a development milestone, a release candidate or some point of software stability achieved within the lifecycle of the development process. As such, it’s not unreasonable to think that at times it would be necessary to perform a git tag clone, rather than a clone from tip of a development branch. It’s not hard to do, either. Just perform the clone and specify the tag name with the branch option.
git-clone@tag:~$ git clone --branch 1.0.0-rc.1 http://gitlab.mcnz.com/root/gitlab-made-easy.git
The detached head
As mentioned, there are times when it makes sense to perform a git clone tag operation. However, it does come with a catch.
Normally, when you check out a branch, your workspace or working tree is updated with the code from the last git commit. From there, you can edit code, add files and subsequently commit and push to origin to your heart’s content. However, a tag is normally in the middle of a long commit history. There are commits before it, and there are commits after it. This creates an unusual situation, as you can’t add any new commits without disturbing the git blockchain.
As such, when you git clone a tag, there is a good chance you will end up in a detached head state. This isn’t the end of the world. You can compile the code you pulled down from your GitHub or GitLab server without a problem. But you won’t be able to make changes and easily merge back to master. You’ll have to jump through some hoops if you plan to do so.
But if that one caveat about the detached head doesn’t scare you off, don’t hesitate to perform a git clone tag. In many instances, especially when working with git submodules or running continuous integration pipelines, a git clone tag operation makes sense.
Become a Git power user
Want to become a Git power user? Take a look at the following Git articles and tutorials
- How to do a Git clean up of branches and commits
- Learn to rebase onto master and rebase from the master branch
- Squash all Git commits on a branch down to one
- Shelve your changes with Git stash pop and apply
- Easily explain the Git vs GitHub difference
- Add a shallow git clone of depth 1 do your Jenkins jobs
- Set up a local Git server with a bare Git repo