Composable helpers for common multi-step git workflows.
Each function orchestrates several lower-level Git commands into a
single logical operation. All functions accept a keyword list where the
:config key, when present, must be a Git.Config struct and is
forwarded to every underlying git invocation.
Examples
# Stage everything and commit in one call
{:ok, result} = Git.Workflow.commit_all("feat: ship it", config: cfg)
# Work on a feature branch, then return to the original branch
{:ok, result} = Git.Workflow.feature_branch("feat/cool", fn opts ->
File.write!("cool.txt", "cool")
{:ok, :done} = Git.add(files: ["cool.txt"], config: opts[:config])
{:ok, _} = Git.commit("feat: cool", Keyword.take(opts, [:config]))
{:ok, :worked}
end, merge: true, config: cfg)
Summary
Functions
Amends the last commit.
Stages all changes and commits with the given message.
Creates a feature branch, runs a function on it, and returns to the original branch.
Merges a branch with --squash and commits with the given message.
Fetches from a remote and integrates changes using rebase or merge.
Functions
@spec amend(keyword()) :: {:ok, Git.CommitResult.t()} | {:error, term()}
Amends the last commit.
When no :message is provided, the existing commit message is reused.
When :all is true, all changes are staged before amending.
Options
:message- new commit message (default: reuse existing message):all- stage all changes before amending (defaultfalse):config- aGit.Configstruct
Returns {:ok, commit_result} on success.
@spec commit_all( String.t(), keyword() ) :: {:ok, Git.CommitResult.t()} | {:error, term()}
Stages all changes and commits with the given message.
Any additional keyword options (e.g., :allow_empty) are forwarded to
Git.commit/2.
Options
:config- aGit.Configstruct- All other options are passed to
Git.commit/2.
Returns {:ok, commit_result} on success.
@spec feature_branch( String.t(), (keyword() -> {:ok, term()} | {:error, term()}), keyword() ) :: {:ok, term()} | {:error, term()}
Creates a feature branch, runs a function on it, and returns to the original branch.
The function fun receives a keyword list containing the :config key
(when one was provided in opts). It must return {:ok, result} or
{:error, reason}.
After fun completes (successfully or not), the original branch is checked
out to ensure cleanup.
Options
:merge- whentrue, merge the feature branch back into the original branch afterfunsucceeds (defaultfalse):delete- whentrue, delete the feature branch after a successful merge (defaultfalse; requires:mergeto betrue):config- aGit.Configstruct
Returns {:ok, result} where result is the return value of fun, or
the merge result when :merge is true.
@spec squash_merge( String.t(), keyword() ) :: {:ok, Git.CommitResult.t()} | {:error, term()}
Merges a branch with --squash and commits with the given message.
Options
:message- commit message (required):delete- whentrue, delete the source branch after merge (defaultfalse):config- aGit.Configstruct
Returns {:ok, commit_result} on success.
Fetches from a remote and integrates changes using rebase or merge.
Options
:strategy-:rebase(default) or:merge:autostash- stash uncommitted changes before syncing and pop after (defaulttrue):remote- remote name (default"origin"):branch- branch to sync with (defaults to the upstream tracking branch):config- aGit.Configstruct
Returns {:ok, :synced} on success.