So you found a tag that represents a pristine release snapshot and now you want to build a tiny patch or a wild experiment without destroying the timeline of human progress. Good move. Branching from a tag gives you a stable starting point to work from and keeps the history neat enough that your team will thank you instead of sending passive aggressive GIFs.
First locate the tag that points to the commit you care about. If the tag is already local run this command and bask in the list of tags.
git tag
If the tag lives on the central server but not in your clone fetch remote tags with this polite request.
git fetch --tags
Pick the tag name that matches the release or build you want, for example v1.2.3. Verify which commit the tag points at if you are the paranoid but careful sort.
git rev-parse v1.2.3
Now make the branch. You have two simple, supported ways to do this depending on your Git version and taste for verbs.
git checkout -b my-hotfix v1.2.3
git switch -c my-hotfix v1.2.3
Either command starts your branch at the tagged commit and checks it out so you can start making changes. This beats checking out the tag by itself which leaves you in a place where new commits vanish if you blink.
If this is part of a release workflow prefer annotated tags for human friendly messages and easy auditing. Annotated tags also carry a signature if you like that sort of thing.
Share your branch so other humans and CI systems can see it. To push the branch do this.
git push origin my-hotfix
To push and set the upstream in one tidy move use this.
git push -u origin my-hotfix
Now collaborators can fetch and check out the branch like any other feature branch. No mystery, no phantom commits.
Checking out a tag directly without creating a branch results in a detached HEAD state. That means any commits you make do not belong to a named branch and can be accidentally discarded. If you see detached HEAD in git status you are in that awkward place.
git status
After creating a branch verify it is tracking the remote branch and points to the right commit.
git branch -vv
git show --no-patch --format=%H my-hotfix
Recap The process is short and glorious. Find the tag, branch from it, push the branch, and do not leave yourself in detached HEAD limbo. Now go fix that bug or break things in a branch where it is safe to do so. If things go wrong you can always blame the tag and call it a learning experience.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.