17

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 <repository adress>

git tag -a testag -m 'test'

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

fatal: Failed to resolve 'HEAD' as a valid ref.
Maxime Lorant
  • 34,607
  • 19
  • 87
  • 97
Ahmad
  • 2,110
  • 5
  • 26
  • 36

5 Answers5

26

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 :-)

sebastianr
  • 657
  • 1
  • 7
  • 10
25

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.

Melebius
  • 6,183
  • 4
  • 39
  • 52
8

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

Mukesh
  • 7,630
  • 21
  • 105
  • 159
5

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.

arush436
  • 1,748
  • 20
  • 20
3

If you have access to the remote repository

cd /path/to/remote/repository
git config --bool core.bare true
raffi
  • 139
  • 1
  • 9
  • 2
    What does that do precisely? – Francis Davey Jan 23 '14 at 17:56
  • According to this page http://bitflop.com/document/111 "A "bare" repository in Git just contains the version control information and no working files (no tree) and it doesn't contain the special .git sub-directory. Instead, it contains all the contents of the .git sub-directory directly in the main directory itself." – raffi Jul 31 '14 at 15:18