I am cloning a single branch from a repository and creating a tag in a python script. The commands are as follows.
git clone -b master --single-branch
If you have access to the remote repository
cd /path/to/remote/repository git config --bool core.bare true
I had the same issue. You have to commit first before tagging
git commit
because you put tags on commits. So when there is no commit (like in your situation), you can't create a tag.
I had the same problem. I cloned from a bare repo and tried to use 'git tag' in that cloned repo, and that is where I was getting the error. To fix it I had to at least one push up to master before I could begin tagging. Hope this helps.
I also faced git tag: fatal: Failed to resolve 'HEAD' as a valid ref
issue when I was missing -m in the following command.(during tag creation)
git tag -a testtag 'test'
changing to
git tag -a testtag -m 'test'
fixed the issue
I ran into the same issue and was able to fix it by changing from
git tag -a testtag -m 'test'
to
git tag -a testtag -m "test"
I was running in Windows 7. Hope this helps :-)