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.
Checks out the main_branch of a repository, stashing uncommitted
changes first if necessary.
Returns churn metrics — the most frequently changed files.
Clones a repository from url to path.
Clones a repository from url to target_path.
Creates a commit with the given message in a repository.
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.
Shows diff of changes.
Ensures a repository is cloned. If it already exists, updates it.
Returns a tree string of existing (already-cloned) repositories.
Fetches all remotes in a repository.
Fetches from origin in the given repository path.
Returns the currently checked-out branch name.
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.
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.
Checks if the GitHub CLI (gh) is available.
Checks if the GitLab CLI (glab) is available.
Returns true if the repository has stash entries.
Returns true if there are uncommitted changes in the repository.
Shows commit history (log).
Marks a conflicted file as resolved (after manual fix).
Aborts a merge in progress.
Pulls from origin using the repository's main_branch.
Pulls from origin for the given branch (default: "main").
Sets Git user name, email, and URL rewrite rules globally.
Configures Git credentials (SSH key path or credential helper).
Stages all changes and creates a commit with the given message.
Stashes uncommitted changes if the working tree is dirty.
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.
Checks out the main_branch of a repository, stashing uncommitted
changes first if necessary.
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 url to target_path.
Creates a commit with the given message in a repository.
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.
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.
Fetches all remotes in a repository.
Fetches from origin in the given repository path.
Returns the currently checked-out branch name.
@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.
@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 gh_available?() :: boolean()
Checks if the GitHub CLI (gh) is available.
@spec glab_available?() :: boolean()
Checks if the GitLab CLI (glab) is available.
Returns true if the repository has stash entries.
Returns true if there are uncommitted changes in the repository.
Shows commit history (log).
Marks a conflicted file as resolved (after manual fix).
Aborts a merge in progress.
Pulls from origin using the repository's main_branch.
Pulls from origin for the given branch (default: "main").
Sets Git user name, email, and URL rewrite rules globally.
Configures Git credentials (SSH key path or credential helper).
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}.
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.