Skip to main content

Module command

Module command 

Source
Expand description

Command execution primitives.

Every git subcommand wrapper is a struct that implements GitCommand. The trait gives each command:

Under the hood, each command delegates to a shared CommandExecutor that spawns git via tokio::process::Command, captures stdout/stderr, and maps non-zero exits to Error::CommandFailed.

§The two-tier output model

Commands with unstructured output — porcelain that varies by git version, locale, and config — return CommandOutput. Callers can treat stdout as bytes or pass it through a parser in crate::parse.

Commands whose output is stable enough to decode return typed values directly. Examples:

§Escape hatches

Every command supports arg, args, flag, and option. Raw args are appended after the command’s typed flags, so they compose naturally:

let repo = Repository::open("/repo")?;
// `--shortstat` isn't on DiffCommand yet — fine, append it raw:
let out = repo.diff().cached().arg("--shortstat").execute().await?;
println!("{}", out.stdout);

Modules§

add
git add — add file contents to the index.
bisect
git bisect — find the commit that introduced a bug via binary search.
branch
git branch — list, create, or delete branches.
cat_file
git cat-file — provide content or type/size information for repository objects.
checkout
git checkout — switch branches or restore working tree files.
cherry_pick
git cherry-pick — apply the changes introduced by some existing commits.
clone
git clone — clone a repository into a new directory.
commit
git commit — record changes to the repository.
config
git config — get and set repository or global options.
describe
git describe — describe a commit using the most recent reachable tag.
diff
git diff — show changes between commits, trees, and the working tree.
fetch
git fetch — download objects and refs from another repository.
for_each_ref
git for-each-ref — output information on each ref matching a pattern.
grep
git grep — print lines matching a pattern.
hash_object
git hash-object — compute object ID and optionally create a blob from a file.
init
git init — create an empty Git repository or reinitialize an existing one.
log
git log — show commit logs.
ls_files
git ls-files — show information about files in the index and working tree.
ls_tree
git ls-tree — list the contents of a tree object.
merge
git merge — join two or more development histories together.
mv
git mv — move or rename a file, directory, or symlink.
pull
git pull — fetch from and integrate with another repository or a local branch.
push
git push — update remote refs along with associated objects.
rebase
git rebase — reapply commits on top of another base tip.
reflog
git reflog — manage and inspect reflog information.
remote
git remote — manage set of tracked repositories.
reset
git reset — reset current HEAD to the specified state.
restore
git restore — restore working tree files.
rev_parse
git rev-parse — pick out and massage parameters.
rm
git rm — remove files from the working tree and from the index.
show
git show — show various types of objects.
show_ref
git show-ref — list references in a local repository.
stash
git stash — stash the changes in a dirty working directory away.
status
git status — show the working tree status.
submodule
git submodule — initialize, update, or inspect submodules.
switch
git switch — switch branches (modern successor to checkout).
symbolic_ref
git symbolic-ref — read or modify a symbolic ref (most commonly HEAD).
tag
git tag — create, list, delete, or verify tags.
update_ref
git update-ref — update the object name stored in a ref safely.
worktree
git worktree — manage multiple working trees attached to the same repository.

Structs§

CommandExecutor
Shared machinery used by every GitCommand to spawn git.
CommandOutput
Captured output from running a git command.

Constants§

DEFAULT_COMMAND_TIMEOUT
Default timeout applied when none is configured on the executor.

Traits§

GitCommand
Trait implemented by every git subcommand wrapper.

Functions§

find_git
Locate the git binary, returning Error::GitNotFound if missing.
git_version
Run git --version and return the raw version string.