0

I successfully cloned a branch branchX on a remote git repo and wanted to use a code base at a certain tag tagX. I did as mentioned here to checkout to the tag. But it gives me the following error:

error: pathspec 'tagX' did not match any file(s) known to git. 

How to resolve this error? Is there an alternative way to point to the tag?

3
  • 1
    Execute git tag command and check whether the tag is on the list. Commented Apr 2, 2019 at 5:38
  • Did you use the option --single-branch? Commented Apr 2, 2019 at 5:49
  • @ElpieKay Nope. I didn't. I used git clone <repo> --branch branchX to clone. Commented Apr 2, 2019 at 5:58

1 Answer 1

3

You have to fetch all tags from the remote. Execute the command git fetch --tags and then try to check out.

Sign up to request clarification or add additional context in comments.

4 Comments

Yes. When you checkout to a tag, Git will move the HEAD position to an old commit. That is why it says "the HEAD is detached".
So, if I want to make changes, I have to create a new branch and merge? Is that the only solution?
What you can do is create a new branch using git checkout -b feature/something. Then you will have a new branch which is based on the commit referenced by the tag. Then the head will move to the new branch. It won't be a detached state.
@skrowten_hermit You could commit from this detached HEAD state, without branching, and merge later into an existing branch, but there's no reason not to create a branch, since it's their very purpose (at virtually no cost).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.