Git tag: fatal: Failed to resolve 'HEAD' as a valid ref

I clone one branch from the repository and create a tag in a python script. The commands are as follows.

git clone -b master --single-branch <repository adress> git tag -a testag -m 'test' 

It successfully clones, but when it comes to adding a tag, it breaks with the following error:

 fatal: Failed to resolve 'HEAD' as a valid ref. 
+7
git
source share
5 answers

I had the same problem. Before you tag

 git commit 

because you put tags on commits. Therefore, when there is no commit (as in your situation), you cannot create a tag.

+16
source share

I ran into the same problem and was able to fix it by changing it with

 git tag -a testtag -m 'test' 

to

 git tag -a testtag -m "test" 

I worked on Windows 7. Hope this helps :-)

+13
source share

I had the same problem. I cloned from a pure repo and tried to use the "git tag" in the cloned repo, and that was where I got the error. To fix this, I had to at least one push up to master before I can start tagging. Hope this helps.

+4
source share

If you have access to a remote repository

  cd / path / to / remote / repository
 git config --bool core.bare true
+3
source share

I also ran into the git tag: fatal: Failed to resolve 'HEAD' as a valid ref problem when I was missing -m in the following command (when creating the tag)

 git tag -a testtag 'test' 

changes to

 git tag -a testtag -m 'test' 

fixed problem

+2
source share

All Articles