A simple Git versioning utility that generates version strings based on Git repository state.
go install github.com/fxsml/gitversion@latestmake buildgitversionOutput: main-ge7e38cf (when on main branch without tags)
Or: v1.0.0-5-ge7e38cf (when 5 commits ahead of v1.0.0 tag)
gitversion helpgitversion -detailedOutput:
Version: main-ge7e38cf
Commit: e7e38cf7d71fe815c4f3bde53ad3bb23e57f5a5f
Branch: main
Default Branch: main
Latest Tag: (none)
Build Time: 2025-11-25T11:11:47Z
Dirty: clean
gitversion -path /path/to/repogitversion -shortgitversion -default-branch masterThe tool uses different strategies based on whether you're on the default branch:
- At tagged commit: Uses tag name (e.g.,
v1.0.0) - Ahead of tag: Uses
git describeformat (e.g.,v1.0.0-5-g1234567) - No tags in history: Uses
{branch-slug}-g{short-commit-hash}
- Always: Uses
{branch-slug}-g{short-commit-hash}(regardless of tags)
- Dirty working tree: Appends timestamp suffix
-YYYYMMDDHHMMSS - Note: Only tracks modifications to tracked files, ignores untracked files
Sanitizes the branch name: replaces / and _ with -, keeps only alphanumeric and -
- Auto-detected from
origin/HEADor falls back tomain/master - Can be overridden with
-default-branchflag - Important: Determines whether to use git describe format or simple branch-commit format
| Branch | Position | Clean/Dirty | Output |
|---|---|---|---|
| main (default) | at tag v1.0.0 | clean | v1.0.0 |
| main (default) | at tag v1.0.0 | dirty | v1.0.0-20251125115903 |
| main (default) | 5 commits after v1.0.0 | clean | v1.0.0-5-gabc123d |
| main (default) | no tags | clean | main-gabc123d |
| main (default) | no tags | dirty | main-gabc123d-20251125115903 |
| feature/new-feature | any | clean | feature-new-feature-gabc123d |
| feature/new-feature | any | dirty | feature-new-feature-gabc123d-20251125115903 |
make testmake test-covermake covermake allRun make help to see all available targets.
MIT License - Copyright 2025 Steve