Wdyt about the following code? There is no need for sed and I think intention is pretty clear

```bash
head="$(git rev-parse HEAD)"
tag="$(git tag --points-at $head)"

if [ -n "$tag" ]; then
  echo $tag
else
  echo $head
fi
```