Thanks to visit codestin.com
Credit goes to mtth.github.io

Important
git-draft is WIP.

Synopsis

git draft [options] [--new] [--accept…​ | --no-accept] [--bot BOT] [--edit]
                    [TEMPLATE [VARIABLE…​] | -]
git draft [options] --quit
git draft [options] --list-events [DRAFT]
git draft [options] --list-templates
git draft [options] --show-template [--edit] TEMPLATE

Description

git-draft is a git-centric way to edit code with AI.

Its workhorse command is git draft (shorthand for git draft --new) which suggests code changes using LLMs. Prompts can be specified inline or via customizable templates. Prompt templates can be augmented with information about the files in the repository, and give the LLM access to tools for reading and writing files. Once the response has been received and changes applied, a commit is created in a dedicated draft branch. This command can be repeated as many times as needed within a draft branch to iterate on the changes. Manual changes can of course be included.

Once satisfied with the changes, run git draft --quit to return to the original branch, keeping the working directory’s current state.

Options

-a
--accept
--no-accept

Merge generated changes automatically, updating the working directory. This option can be repeated up to 3 times, with the following behavior at each level:

  • -a: Merge changes conservatively, flagging any conflicts for manual user resolution.

  • -aa: Merge changes aggressively, resolving all conflicts in favor of the generated change.

  • -aaa: Merge changes aggressively (same as -aa) then run --quit.

By default, changes are not merged - keeping the working directory untouched. A different default can be set in the configuration file. When doing so, the --no-accept flag can be used to disable merging at CLI invocation time.

--batch

Disable interactive feedback. If a bot needs more information, its question will be persisted and displayed when creating the next draft.

-b BOT
--bot=BOT

Set bot name. The default is to use the first bot defined in the configuration.

-o OPTION
--bot-option=OPTION

Set bot option. Each option has the format <key>[=<value>] (if the value is omitted, it will default to true). This will override any option set in configuration files.

-e
--edit

Enable interactive editing of draft prompts and templates. When used with --new, it opens an editor with the rendered prompt. The updated prompt will be used by the bot after the editor exits. When used with --templates, it opens an editor with the selected template. The template will be created automatically if it did not already exist.

-h
--help

Show help message and exit.

-E
--list-events

Display all events corresponding to a draft.

--log-path

Show log path and exit.

-N
--new

Generate a draft commit for a given prompt. - can be specified instead of a template name to read the prompt from stdin. Otherwise if no template is specified and stdin is a TTY, $EDITOR will be opened to enter the prompt.

-Q
--quit

Go back to the draft’s origin branch, keeping the working directory’s current state. This will delete the draft branch and its upstream. Generated commits and the draft branch’s final state remain available via refs/drafts.

-S
--show-template

Display the corresponding template’s contents or, if the --edit option is set, open an interactive editor with its contents.

-T
--list-templates

Lists available templates.

--version

Show version and exit.

Examples

Commit graphs

This section shows representative commit histories in draft branches for various scenarios.

When the working directory is clean, a single commit is created and set as the draft branch’s upstream (suffixed with +).

o draft! prompt: <prompt> (draft/123+, refs/drafts/123/1)
o <some commit> (main, draft/123)

If the working directory is dirty, a sync commit is added to identify the LLM-generated changes.

o draft! prompt: <prompt> (draft/123+, refs/drafts/123/1)
o draft! sync(prompt)
o <some commit> (main, draft/123)

If merging is enabled, the merge commit will have both the LLM-generated changes and manual edits as parents.

o Merge (draft/123, draft/123/+)
|\
| o draft! prompt: <prompt> (refs/drafts/123/1)
o | draft! sync(merge)
| o draft! sync(prompt)
|/
o <some commit> (main)

Otherwise, the user is free to incorporate the changes as needed. Note that the steps above can be repeated arbitrarily many times within a given draft branch, both with and without automatic merging.

o draft! prompt: <prompt3> (draft/123+, refs/drafts/123/3)
o <a manual commit> (draft/123)
o draft! prompt: <prompt2> (refs/drafts/123/2)
o draft! sync(prompt)
| o draft! prompt: <prompt1> (refs/drafts/123/1)
|/
o <some commit> (main)

Sync commits will be reused if no new changes were added. This can be useful when iterating on a prompt, and discarding results from prior iterations.

o draft! prompt: <prompt3> (refs/drafts/123/3)
| o draft! prompt: <prompt2> (refs/drafts/123/2)
|/ o draft! prompt: <prompt1> (refs/drafts/123/1)
| /
|/
o draft! sync(prompt)
o <some commit> (main)

See also

git(1)