Git utilities for repository management, configuration and synchronisation.
Provides functionality for configuring Git, cloning repositories, synchronising changes and managing multiple projects.
Security
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.
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.
Creates a GitHub PR via the GitHub CLI (gh).
Creates a GitLab MR via the GitLab CLI (glab).
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.
Lists open issues via the GitHub CLI (gh).
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 and counts how many times
each file has been modified. Results are sorted by churn count descending.
Options
:period— Time period for git log (default:"6.months"):top— Return only the top N files (default: 20):branch— Git branch to analyze (default: current branch)
Examples
iex> Apero.Git.churn(".")
{:ok, [%{file: "lib/foo.ex", churn: 15}, ...]}
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.
Creates a GitHub PR via the GitHub CLI (gh).
@spec create_glab_mr(binary(), binary(), binary(), keyword()) :: {:ok, binary()} | {:error, binary()}
Creates a GitLab MR via the GitLab CLI (glab).
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.
Lists open issues via the GitHub CLI (gh).
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.