0

I'm having trouble creating a git alias to delete a tag remotely.

I have the following in my .gitconfig:

[alias]
  deltag = push origin :refs/tags/$1

Running the deltag alias after deleting a tag locally (with git tag -d testtag) results in this error:

$ git deltag testtag
error: src refspec testtag does not match any.
error: failed to push some refs to 'ssh://........'

Attempting to run this alias before deleting it locally results in this instead:

$ git deltag testtag
remote: warning: Deleting a non-existent ref.
To ssh://........
- [deleted]         $1

What is the correct syntax to use for this alias?

Tim Malone
  • 3,364
  • 5
  • 37
  • 50

1 Answers1

3

I solved this by hunting around on StackOverflow and putting some other answers together.

There may be other solutions too, but turning the alias into a shell command successfully passes the tag argument through:

[alias]
  deltag = !sh -c 'git push origin :refs/tags/$1' -

Or even better, combining both the local and remote delete into one alias:

[alias]
  deltag = !sh -c 'git tag -d $1 && git push origin :refs/tags/$1' -

The output:

$ git deltag testtag
Deleted tag 'testtag' (was be73a23)
To ssh://.......
 - [deleted]         testtag
Tim Malone
  • 3,364
  • 5
  • 37
  • 50