Local Git operations — clone, commit, pull, push, branch, stash, merge, etc.
All user-supplied values (commit messages, branch names, file paths) are passed as argument lists — never interpolated into shell strings — to prevent shell injection attacks. Arguments are shell-quoted before being joined into the final command line, so values containing whitespace, quotes or shell metacharacters are safe.
Summary
Functions
Stages files in a repository.
Shows who last modified each line of a file (blame).
Returns true if the given branch exists locally or remotely.
Builds churn arguments for git log.
Builds git options for a repository path and optional timeout.
Checks out the main_branch of a repository, stashing uncommitted
changes first if necessary.
Cherry-picks a commit.
Returns churn metrics — the most frequently changed files.
Clones a repository from url to path.
Clones a repository from a URL to a target path.
Creates a commit with the given message in a repository.
Commits all staged changes.
Gets a Git configuration value (local → global → system).
Gets a Git configuration value from the global scope.
Gets a Git configuration value from the local (repo) scope.
Lists files with merge conflicts in the repo.
Checks if a repository contains no commits.
Creates a new branch.
Deletes a branch.
Shows diff of changes.
Ensures a repository is cloned. If it already exists, updates it.
Returns a tree string of existing (already-cloned) repositories from a list
of {:repo_exists | :repo_error, map(), ...} tuples.
Fetches all remotes in a repository.
Fetches all repository changes from origin.
Fetches from origin in the given repository path.
Fetches repository updates from origin.
Gets the commit count for a repository.
Returns the currently checked-out branch name.
Gets the current commit hash for a repository.
Gets the first commit hash for a repository.
Returns the configured Git user email, or nil if not set.
Returns the configured Git user name, or nil if not set.
Returns the machine's hostname.
Gets the short (7-char) commit hash for HEAD.
Returns the current system user email from the USER_EMAIL env variable,
falling back to "user@domain.com".
Returns the current system user name.
Returns a map with the current Git user information.
Gets the current working directory.
Checks if gh is available.
Checks if glab is available.
Returns true if the repository has stash entries.
Returns true if there are uncommitted changes in the repository.
Returns the list of all local branches.
Shows commit history (log).
Marks a conflicted file as resolved (after manual fix).
Merges a branch into the current branch.
Aborts a merge in progress.
Merges a commit into the current branch.
Parses churn output.
Pulls from origin using the repository's main_branch.
Pulls from origin for the given branch (default: "main").
Rebase a branch onto another.
Reverts a commit.
Runs a git command with options.
Runs a system command with telemetry instrumentation.
Sets Git user name, email, and URL rewrite rules globally.
Sets up a credential helper for git.
Configures Git credentials (SSH key path or credential helper).
Sets up an SSH key for git.
Quotes a binary string for safe shell use.
Squashes commits into one.
Stages all changes.
Stages all changes and creates a commit with the given message.
Stashes uncommitted changes if the working tree is dirty.
Restores stashed changes.
Pushes stash entries in a repository.
Synchronises a list of repositories (checkout → fetch → pull).
Updates an existing repository by fetching from origin.
Functions
Stages files in a repository.
Pass :all to stage everything, a list of paths, or a single path binary.
Shows who last modified each line of a file (blame).
Returns true if the given branch exists locally or remotely.
Builds churn arguments for git log.
Builds git options for a repository path and optional timeout.
Checks out the main_branch of a repository, stashing uncommitted
changes first if necessary.
Cherry-picks a commit.
Returns churn metrics — the most frequently changed files.
Runs git log --name-only for the given period or max commits and counts
how many times each file has been modified. Results are sorted by churn
count descending.
When include_authors: true, uses --format=COMMIT:%an to track which
authors touched each file, so callers can compute risk scores like
churn * (1 + log(num_authors)).
Options
:period— Time period for git log (default:"6.months"). Ignored if:max_commitsis set.:max_commits— Limit to the last N commits (uses--max-count). Overrides:period.:no_merges— Exclude merge commits via--no-merges(default:false):top— Return only the top N files (default: 20):branch— Git branch to analyze (default: current branch):include_authors— Track distinct authors per file (default:false). Whentrue, each result includes:authors(list of author names).:timeout— Command timeout in milliseconds (default:nil, meaning Arrea's default). Passed toArrea.Command.execute/2.
Examples
iex> Trebejo.Git.Local.churn(".")
{:ok, [%{file: "lib/foo.ex", churn: 15}, ...]}
iex> Trebejo.Git.Local.churn(".", max_commits: 1000, no_merges: true, include_authors: true)
{:ok, [%{file: "lib/foo.ex", churn: 15, authors: ["Alice", "Bob"]}, ...]}
Clones a repository from url to path.
Clones a repository from a URL to a target path.
Creates a commit with the given message in a repository.
Commits all staged changes.
Gets a Git configuration value (local → global → system).
Accepts an optional cd: option to scope the lookup to a specific
repository directory.
Gets a Git configuration value from the global scope.
Accepts an optional cd: option (kept for signature parity with
config/2; ignored at the global scope).
Gets a Git configuration value from the local (repo) scope.
Accepts an optional cd: option to scope the lookup to a specific
repository directory.
Lists files with merge conflicts in the repo.
Checks if a repository contains no commits.
Creates a new branch.
Deletes a branch.
Shows diff of changes.
@spec ensure_clone(nil) :: {:error, :no_repo_defined}
Ensures a repository is cloned. If it already exists, updates it.
Accepts a single repo map, a list of repo maps, or nil.
Returns a tree string of existing (already-cloned) repositories from a list
of {:repo_exists | :repo_error, map(), ...} tuples.
Fetches all remotes in a repository.
Fetches all repository changes from origin.
Fetches from origin in the given repository path.
Fetches repository updates from origin.
Gets the commit count for a repository.
Returns the currently checked-out branch name.
Gets the current commit hash for a repository.
Gets the first commit hash for a repository.
@spec get_git_user_email() :: binary() | nil
Returns the configured Git user email, or nil if not set.
@spec get_git_user_name() :: binary() | nil
Returns the configured Git user name, or nil if not set.
@spec get_hostname() :: binary()
Returns the machine's hostname.
Gets the short (7-char) commit hash for HEAD.
@spec get_system_user_email() :: binary()
Returns the current system user email from the USER_EMAIL env variable,
falling back to "user@domain.com".
@spec get_system_user_name() :: binary()
Returns the current system user name.
@spec get_user_info() :: map()
Returns a map with the current Git user information.
Falls back to system user information if Git is not configured.
@spec get_working_directory() :: binary()
Gets the current working directory.
@spec gh_available?() :: boolean()
Checks if gh is available.
@spec glab_available?() :: boolean()
Checks if glab is available.
Returns true if the repository has stash entries.
Returns true if there are uncommitted changes in the repository.
Returns the list of all local branches.
Shows commit history (log).
Marks a conflicted file as resolved (after manual fix).
Merges a branch into the current branch.
Aborts a merge in progress.
Merges a commit into the current branch.
Parses churn output.
Pulls from origin using the repository's main_branch.
Pulls from origin for the given branch (default: "main").
Rebase a branch onto another.
Reverts a commit.
Runs a git command with options.
Runs a system command with telemetry instrumentation.
Sets Git user name, email, and URL rewrite rules globally.
Sets up a credential helper for git.
Configures Git credentials (SSH key path or credential helper).
Sets up an SSH key for git.
Quotes a binary string for safe shell use.
Squashes commits into one.
Stages all changes.
Stages all changes and creates a commit with the given message.
Stashes uncommitted changes if the working tree is dirty.
Returns {:ok, {:stashed, branch}}, {:ok, :clean}, or {:error, reason}.
Restores stashed changes.
Pushes stash entries in a repository.
Options
:message— stash description (default:"auto-stash"):include_untracked— include untracked files (default:true)
Synchronises a list of repositories (checkout → fetch → pull).
Updates an existing repository by fetching from origin.