Set up GitVersion with an AI agent

Use this guide with Claude Code, Codex, GitHub Copilot, or Antigravity in the repository you want to version. The agent should recommend settings from your release process and check them against existing history before adopting them.

The primary path uses GitVersion v7's established CLI, built from src/ in the GitVersion source repository. The experimental new-cli/ tree has a different command structure and is outside this guide. If you retain an existing v6 installation, use the optional v6 path.

Give the agent this task

Use Copy setup prompt, or choose your agent from Use with an agent, to copy the task with this guide's links. Paste it into the agent session for your repository. You can also view the Markdown guide or select the prompt below if copying is unavailable.

Open your repository in your agent and provide this prompt together with this guide's URL or a local copy:

Read the GitVersion AI-agent onboarding guide. Inspect this repository's
existing GitVersion installation, configuration, branch/tag history and
release workflow. Recommend a pinned v7 distribution and minimal configuration
that match our workflow, explaining alternatives and assumptions. Keep v6 as
an option if we already depend on it or choose its compatibility guarantees.
Verify that the pinned v7 artifact exists. If none is suitable, propose a
source build from a reviewed v7 commit in a separate GitVersion checkout,
using its pinned SDK and src/GitVersion.App; record the SHA and executable.

Show proposed installation commands and file changes before applying them
unless I have already authorized those actions. After installation, verify
the selected executable's version. For v7, run gitversion --cli-schema using
that executable and read its JSON to discover commands, aliases, options,
arguments and accepted values before constructing commands. If schema export
is unavailable, use that executable's --help rather than guessing commands.
For v7, run gitversion config validate --config <candidate-file> to check
the intended candidate first, using its absolute path.
Inspect the effective configuration, then compare baseline and candidate
results on representative existing branches, tags and commits. Explain
unexpected versions before adjusting settings. Report evidence, remaining
questions and the final diff.

Preserve existing files, user edits and Git history. Do not create tags or
commits, fetch or normalize refs merely to make a sample work, install globally,
change authentication, publish, push or configure CI unless authorized.
Do not read or expose secrets. Follow this repository's instructions.

For reproducible team use, pin the guide to a reviewed GitVersion source commit or vendor a local copy and record its revision. A URL in an instruction file does not guarantee that an agent retrieves it: explicitly ask the agent to read it and report the guide revision and tool version it used.

Give the agent a migration task

For an existing v6.8 installation, use Copy migration prompt or select the text below. The same prompt works with Codex, Claude Code, GitHub Copilot and Antigravity. Follow the v6.8-to-v7.0 recipe rather than starting with a new configuration.

Read the GitVersion AI-agent onboarding guide, its v6.8-to-v7.0 migration
recipe and the linked v6-to-v7 migration guide. Read applicable repository
and agent instructions. Help migrate this repository's existing GitVersion
v6.8 installation to v7.0 while preserving its release policy.

Inventory the exact v6.8 executable, config, tool/integration pins and consumers.
Keep that executable and config available for a baseline. Propose a separately
pinned, verified v7.0 artifact or a reviewed source build; do not assume a stable
v7.0 release exists. Discover commands from each executable's own help/schema.
Show installation commands and file changes before applying them unless I have
already authorized them. Do not replace the v6.8 pin before comparison.

Capture v6.8 JSON and resolved configuration on representative existing refs
and full commit SHAs. Use v7's config migrate to write a separate candidate,
preserve the original and its comments, then validate and inspect the candidate.
Compare v6.8 with its original config against v7.0 with its migrated config
at the same commits and branch contexts, with fetching, normalization, caches
and build-server/file updates disabled. Verify each reported Sha matches the
requested commit; stop and investigate any mismatch. Map renamed fields before
comparing, explain version differences, and report missing history as untested.

Audit CLI scripts, JSON/format consumers, Azure variables, MSBuild properties,
runtime/platform requirements and Docker tags/permissions against the migration
guide. Treat parser, configuration and Git-backend selectors independently;
record their removal schedule and test v7 defaults without compatibility
overrides in an isolated process. Do not change global environment settings.

Return the migration diff, both version pins/invocations, an expected/actual
comparison table, consumer changes, unresolved decisions and rollback steps.
Apply accepted changes only within my authorization. Preserve user edits,
secrets and Git history. Do not create refs, fetch or normalize history, install
globally, change credentials, publish, push or configure CI unless authorized.

1. Inspect before changing anything

The agent should establish:

  • Repository root, current branch and commit, dirty/untracked paths, shallow status, and whether this is a linked worktree.
  • Existing executables and their --version/--help output; local and relevant ancestor tool manifests; GitVersion package references, scripts, and CI tool pins. A PATH executable can differ from the local tool or CI version.
  • Configuration in the working directory and repository root: GitVersion.yml, GitVersion.yaml, .GitVersion.yml, .GitVersion.yaml, and explicit paths in scripts. Resolve ambiguous files explicitly rather than creating another one.
  • OS, architecture, shell, and available .NET SDK/runtime or Docker. Separate the tool's requirements from the language and target frameworks of the application being versioned.
  • Existing release tags, branch names and a bounded history graph; merge, squash or rebase practice; release branches, prerelease channels and version consumers.

Ask about release intent only where the evidence leaves a choice unresolved. For example, a branch named develop does not establish a Git Flow release policy. For a monorepo, agree whether components share one version before choosing settings. Inspect scoped project and workflow files; avoid .env, credential files, authenticated remote URLs and environment dumps.

Record a baseline before editing. Preserve existing configuration and tool pins until the user accepts a replacement. See repository requirements for the history needed for a meaningful calculation.

2. Select and acquire v7

Choose a distribution based on available tooling and intended consumers:

Situation Suggested option Tradeoff
Existing compatible pinned installation Reuse it Align local and CI versions before changing either.
A .NET SDK is already available Pinned local GitVersion.Tool A manifest keeps the project and team on one version. v7 tool installation requires the .NET 10 SDK.
Docker is already available Versioned image, preferably pinned by digest Avoid host .NET setup; account for platform and writable mounts.
Neither SDK nor Docker is appropriate Standalone release archive Select the actual OS/architecture and Linux glibc/musl asset; keep it in a project/task-local location.
.NET assembly/package versions should follow builds Consider GitVersion.MsBuild after CLI verification This changes build behavior; coordinate existing version writers and supported MSBuild hosts.
CI already integrates GitVersion Match the integration's tool pin The action/task version and GitVersion version are separate choices.

GitVersion can calculate versions for JavaScript, Python, Go and other repositories too. Start with JSON output and decide which variable each consumer needs. Refer to installation, MSBuild integration and CI integration for details. Offer workstation-wide package managers or global tools only when the user wants global setup.

Pin a real artifact or source revision

Check published releases and NuGet packages before installing. These are v7 development instructions: documentation for v7 does not establish that a stable v7 package or image is published. Do not let an unversioned install silently select v6. Verify the exact chosen package, archive or image and its provenance; do not invent a tag, asset or checksum file.

For an existing local manifest, inspect its entries before restoring tools:

dotnet tool restore
dotnet tool run dotnet-gitversion -- --version
dotnet tool run dotnet-gitversion -- --help

For a new manifest, create it only when no applicable manifest exists, then install an exact, verified v7 package version. These are templates: replace angle-bracket values before execution.

dotnet new tool-manifest
dotnet tool install GitVersion.Tool --version <verified-v7-package-version>

Preserve other tools in an existing manifest. Do not change feeds or credentials to make installation succeed. If using .NET 10's one-shot dotnet tool exec, verify its version resolution: without a pin or applicable manifest it can download the latest package.

If a suitable v7 artifact is unavailable, offer a source build in a separate GitVersion checkout, at a reviewed v7 commit. Use the SDK pinned in that checkout's global.json, publish src/GitVersion.App/GitVersion.App.csproj, and record the source SHA and resulting executable path. See the source-build example. Building requires restoring dependencies; explain that setup cost before proceeding. Do not build experimental new-cli/ as a substitute.

In the remaining v7 examples, gitversion means the executable you verified. For a local tool replace it with dotnet tool run dotnet-gitversion --; for a source build use dotnet /absolute/path/to/gitversion.dll. Store both the pin and invocation in the handoff.

Discover commands and options

Confirm the executable's version, then ask it for its command grammar:

gitversion --version
gitversion --cli-schema

Read the CLI schema JSON before constructing commands. It describes the available commands and subcommands, aliases, options, positional arguments, value arity and accepted values where available. Include inherited options from parent commands marked recursive: true. Use the selected executable's schema to discover capabilities rather than guessing command names or copying examples from another version.

--cli-schema works outside a Git repository and does not load configuration, calculate a version or write files. This is the CLI grammar, not the configuration JSON Schema used to check YAML. Run it separately from --version, because schema export takes precedence when both flags are supplied.

Schema export requires the v7 argument parser. If the selected executable or temporary v6 parser cannot export it, use that executable's --help and matching reference documentation. Check the discovered command tree before using newly added commands; an older v7 build may not expose them.

Docker mounts and permissions

Use the selected image's exact version/platform. v7 images run as UID/GID 10001:10001; the mounted repository must be writable by that user. On Linux, the non-root checkout owner's UID/GID may be appropriate. v7 handles an unwritable home using a private temporary home inside the container, without extra HOME or DOTNET_CLI_HOME flags. On Docker Desktop, check host file-sharing permissions. Follow Docker repository permissions.

Prefer a disposable standalone clone for Docker experiments. A linked worktree's .git file can point outside the mount, and GitVersion may write repository metadata/cache, so a read-only mount is not a general solution. Mount a candidate configuration deliberately and pass its container path. Do not use recursive permission changes, root or privileged execution as a workaround. Container environment changes do not universally reach the host; use JSON for these checks.

3. Recommend a minimal configuration

Choose defaults that fit how the repository already merges and releases. Present alternatives with evidence and assumptions:

Observed practice Candidate starting point
Short-lived branches merged into main through PRs GitHubFlow/v1
Persistent development and release stages GitFlow/v1
Trunk-based practice Evaluate existing presets first; offer TrunkBased/preview1 only with its experimental status explained.

A preset is a starting point, not a requirement to reorganize branches. Keep workflow, deployment mode and calculation strategy separate. Discuss version increments, tag recognition, labels and package/assembly output needs independently.

For a repository that selects GitHub Flow, this is a minimal v7 candidate:

workflow: GitHubFlow/v1

Add overrides only for a stated requirement. For example, v7 calculation overrides belong under calculation:

workflow: GitHubFlow/v1
calculation:
  tag-prefix: '[vV]?'

That tag prefix is the documented default; confirm it with the selected executable's effective configuration, and do not add it unless explicitly recording it helps the team. Inspect existing tag names before changing it. Output settings belong under output. Use configuration by topic and the reference rather than copying every resolved default into the file.

Save a candidate separately from the existing config, preserving comments and unrelated settings. Select the candidate by absolute path during checks. Do not set next-version or ignore history merely to force a desired example result. For a v6-to-v7 migration, emit a separate candidate with config migrate and review the diff; in-place migration cannot preserve comments.

4. Check structure and resolved settings

Associate the candidate with the matching configuration schema in the editor or a YAML-aware validator. The v7 schema describes nested YAML. Editor schema comments/associations do not require adding a runtime $schema property. Schema validation checks structure; loading and history calculations check additional behavior.

These templates use paths selected during inspection:

gitversion config validate --config <candidate-file> --format json
gitversion --target-path <repository> --config <candidate-file> --show-config
gitversion --target-path <repository> config get calculation.tag-prefix --config <candidate-file>

--show-config displays defaults and overrides. config get returns a JSON scalar for a supported v7 property; it does not return branch-specific inherited behavior or a calculated version. Both need a suitable repository in the established CLI. See configuration queries.

The v7 config validate command checks the candidate without calculating a version or changing files and refs. An explicit file works outside Git and offline. Require a successful exit and a valid result before continuing; --format json writes the result to stdout and diagnostics go to stderr. See configuration validation for supported options, diagnostics and limits.

Successful validation still needs effective-config inspection and history-based verification to establish that versions fit the release workflow.

5. Compare results against real history

Agree on representative existing points and expected behavior before tuning the candidate:

Sample Question to resolve
Current HEAD What version/channel should the next build produce?
Latest reachable release tag and its commit Does GitVersion recognize the released version?
Existing commit after that tag Does the increment match the release policy?
Existing feature/PR branch Are the label, number and consumer version suitable?
Existing merge, release or support branch point Does the version progress as expected across release stages?

Record branch, full commit SHA, tag if applicable, selected tool/config and baseline/candidate results. If a scenario does not exist, mark it untested. Do not create tags, commits or branches to manufacture a sample in the user's repository.

Use the verified v7 executable's branch and commit selection instead of switching the shared checkout. This template selects actual existing refs/commits:

gitversion --target-path <repository> --config <candidate-file> --output json --no-fetch --no-normalize --no-cache --branch <existing-branch> --commit <existing-sha>

Run each sample with the baseline and the candidate. For a v6.8-to-v7.0 upgrade, use the cross-version comparison recipe below: the baseline must run on v6.8 with its original configuration. When no baseline file exists, omit --config for the v7 baseline and record that defaults were used. Keep the same selected file across samples rather than accidentally loading historical configuration. A commit reachable from multiple branches needs explicit branch context; a detached release tag may not reproduce the release branch's calculation.

Use the full commit SHA for --commit. After every baseline and candidate run, verify that the Sha reported in stdout JSON exactly matches that requested SHA. If it differs, discard the result and investigate commit selection and execution context before comparing versions. Do not change refs or history to force a match.

Capture exit status, stdout JSON and stderr separately. Keep build-server context out of local experiments and use JSON without assembly/project/WiX update options. --no-fetch, --no-normalize and --no-cache avoid fetching, build-server normalization and cache writes during comparison. For uncertain environments, use an isolated standalone copy with the existing relevant refs/history, preserving branch identity; do not normalize or synthesize refs just to make the calculation work.

Compare SemVer, FullSemVer, Sha, BranchName, prerelease fields and VersionSourceDistance with the user's expectations. Check variable meanings and the actual package/assembly consumer's constraints. A prerelease number is not a count of CI runs.

When results differ, investigate in this order:

  1. Selected executable/version, parser, config layout and config path.
  2. Available history/tags, branch context and version source.
  3. Increment, mode, inheritance and label policy.
  4. Output formatting and downstream consumers.

Use --diagnose or diagnostic verbosity when needed, keeping logs local and redacting paths, remote details and sensitive history before sharing. Explain one adjustment at a time, rerun affected samples and retain earlier agreed checks. If missing history prevents a conclusion, report the gap and propose an authorized fetch into a disposable clone; allowing a shallow calculation does not prove correctness. Stop for an unresolved release-policy decision instead of tuning indefinitely.

6. Adopt and hand off

Within the user's authorization, apply the minimal accepted config change and retain the selected version pin. Return:

  • Installation method, exact tool version/source SHA, guide revision and invocation.
  • Configuration diff, preset rationale, alternatives and remaining assumptions.
  • Baseline/candidate sample table with expected/actual versions, exit status and untested scenarios.
  • Reproduction commands and any blockers or diagnostic findings.

Check files and refs against the initial inventory and explain intentional changes. Keep user edits intact. Add MSBuild or CI integration only when requested, after CLI results agree. Avoid duplicate assembly-version writers; preserve the selected integration's output contract, including GitVersion_ prefixes where applicable. Consult v7 migration changes before updating consumers. Release creation, tagging, publishing and pushing require their own authorization.

Migrate an existing v6.8 repository to v7.0

Use this recipe when upgrading an existing installation. Read the complete v6-to-v7 migration guide for the selected v7 revision; configuration conversion alone does not migrate scripts or output consumers. Keep the experimental new-cli/ tree outside this upgrade.

Preserve the v6.8 baseline and acquire v7.0 separately

Record the exact v6.8 patch version, executable invocation, configuration path, integration/tool manifest pins and relevant environment variables. Keep the original config, including comments, and inventory every consumer: scripts, JSON readers, custom formats, CI variables and MSBuild properties. If no config exists, record that v6.8 defaults supply the baseline.

Select and acquire v7.0 using the artifact checks above. Keep both executables available, with independently verified versions and requirements. Use a task-local tool path, versioned archive/image or separate reviewed source checkout so acquiring v7 does not replace the team's v6.8 manifest or CI pin. A v7 prerelease or source build must be identified as such.

Before converting configuration, capture resolved settings and baseline JSON with the v6.8 executable at the representative existing points in the history sample table. These are command templates; replace placeholders and use absolute executable/config paths:

<verified-v6.8-executable> <repository> /config <original-v6-config> /showconfig /nofetch /nonormalize /nocache
<verified-v6.8-executable> <repository> /config <original-v6-config> /output json /nofetch /nonormalize /nocache /b <existing-branch> /c <existing-full-sha>

If v6.8 used defaults, omit /config rather than creating a baseline file. Capture stdout, stderr and exit status separately. Verify the reported Sha against each requested commit and retain explicit branch context. Use an isolated copy with existing history when required; do not move refs or manufacture tags to obtain expected results.

Migrate a candidate, validate it and compare both versions

Use the verified v7 executable with its default POSIX parser to convert the original flat YAML into a separate, previously nonexistent candidate. The following commands use gitversion as the verified v7 invocation:

gitversion config migrate --config <original-v6-config> --output <new-v7-config>
gitversion config validate --config <new-v7-config> --format json
gitversion --target-path <repository> --config <new-v7-config> --show-config --no-fetch --no-normalize --no-cache
gitversion --target-path <repository> --config <new-v7-config> --output json --no-fetch --no-normalize --no-cache --branch <existing-branch> --commit <existing-full-sha>

Do not use --in-place or --force for this comparison. Review the nested calculation and output settings, keep workflow at the root, and carry required comments forward when adopting the candidate. If v6.8 had no config file, retain a no-file baseline and inspect v7 defaults or a separate minimal candidate; do not invoke migration on an invented input.

Run the v6.8 baseline and v7 candidate for every agreed sample at the same full SHA and branch context. Use each version's own parser and configuration layout. A v7 run with the original flat file is not a v6.8 baseline. Require successful validation and matching Sha values before comparing results. Do not request build-server output, update assembly/project/WiX files or run a publishing build during this phase.

Compare release versions, prerelease channels, increment policy and counting fields semantically. For example, v6 CommitsSinceVersionSource maps to v7 VersionSourceDistance. In v7, PreReleaseLabel means the full label (beta.99), while PreReleaseLabelName means its name (beta); a same-named property is not always equivalent across versions. Use the migration guide's complete mapping and check consumer requirements. Explain changed calculations before tuning config; do not force parity with next-version or ignored history.

Audit integration changes before switching pins

Use this checklist with the complete migration guide:

Area Required migration check
Scripts and CLI arguments Translate legacy switches to POSIX options using the argument mapping and the selected executable's help/schema. Check logging and machine-readable output channels.
JSON, custom formats and generated outputs Replace removed CommitsSinceVersionSource, map all prerelease fields, and account for added source fields in strict JSON readers.
Azure Pipelines and MSBuild Migrate Azure GitVersion.Property consumers to GitVersion_Property. Apply renamed fields to MSBuild properties too, verify task-host/runtime compatibility and avoid duplicate version writers.
Branch context Check GIT_BRANCH/Git_Branch overrides and provider precedence; they no longer select or move the named branch tip.
Installation and platforms Check .NET 10/11 runtime and MSBuild host requirements, RID-specific tool packages and Intel/Apple Silicon macOS support. A source build uses its pinned SDK.
Docker Select a published v7 tag/digest and supported distribution/architecture. Check UID/GID 10001:10001 and writable repository mounts using the non-root migration guidance.
Compatibility selectors Audit parser, configuration and backend environment variables independently, including the retired GITVERSION_USE_V6_ARGUMENT_PARSER variable.

In an isolated invocation, remove inherited compatibility selectors and test the default v7 parser, nested config and managed backend. Do not unset variables in the user's global environment. The temporary GITVERSION_ARGUMENT_PARSER_VERSION=v6, GITVERSION_CONFIGURATION_VERSION=v6 and GITVERSION_GIT_BACKEND=libgit2 selections are independent v7.0 migration aids, scheduled for removal in v7.1; they do not run the old v6.8 executable. The selectors themselves are removed in v8. Record any temporary fallback and its removal plan.

Adopt with a comparison record and rollback path

Return a table containing branch, full SHA, both executable/config pins, expected versions, actual values, exit status and explained differences. Mark absent scenarios untested. Include consumer changes and any decisions that need the user; do not claim output compatibility from schema validation alone.

Within the user's authorization, update the tool/config and integration pins together after acceptance, preserve unrelated edits and comments, then repeat the agreed checks with the adopted invocation. CI/integration builds need their own authorized validation, including package or assembly outputs where relevant. Keep the exact v6.8 executable/config/pins and a focused rollback diff until migration is accepted. Rolling back restores those files and pins; it does not reset the repository, rewrite history or publish another release.

Optional v6 compatibility path

Retain v6 when the user chooses it or an existing pin depends on it. Verify that exact published version and its help; do not automatically migrate its config. v6 uses flat settings, for example:

workflow: GitHubFlow/v1
tag-prefix: '[vV]?'

Use the appropriate flat configuration schema, such as the 6.3 schema for compatible v6 versions, rather than the nested v7 schema. Schema versions do not necessarily match tool patch numbers. Keep v6 examples in a separate recipe:

<verified-v6-executable> <repository> /config <candidate-file> /showconfig
<verified-v6-executable> <repository> /config <candidate-file> /output json /nofetch /nonormalize /nocache /b <existing-branch> /c <existing-sha>

Use the same baseline/candidate history loop, but read v6 variable names, such as CommitsSinceVersionSource, from that tool's reference. config get, config migrate, config validate and --cli-schema are v7 features, unavailable in published v6 binaries. See the migration guide before selecting v7, including the independent temporary configuration/parser/backend selectors and their removal schedule. v7's temporary flat-v6 configuration mode is distinct from running a v6 executable.

Optional agent discovery adapters

The explicit prompt above works without modifying instruction files. GitVersion's own maintainer instructions are not automatically discovered from the user's repository. For repeated use, merge a small task-specific pointer into that repository's existing instructions, preserving their contents and scope:

Agent Where to put the pointer Discovery caveat
Codex Existing AGENTS.md Overrides and nearer directory instructions affect discovery; see Codex guidance.
Claude Code Existing CLAUDE.md, optionally an @path import of a local guide Current AGENTS.md support depends on client version/settings and existing CLAUDE files; see Claude memory.
GitHub Copilot .github/copilot-instructions.md AGENTS.md and path-specific support vary by IDE/feature; check the support matrix.
Antigravity Existing AGENTS.md/GEMINI.md or a scoped .agents/rules/*.md file Modular rules require valid activation frontmatter; see Antigravity rules.

For example, adapt this pointer with the reviewed guide's location:

When asked to adopt or adjust GitVersion, read our pinned copy of the
GitVersion AI-agent onboarding guide at <reviewed-guide-location>.
Use its inspect/propose/verify flow, preserve existing files and refs,
and report the tool/config versions and history samples checked.

These are optional adapters to one canonical guide. Avoid copying the full procedure into four files, changing global agent settings, or assuming a link is an automatic import. Verify discovery in the actual client, then have the agent explicitly read the guide.