git.merge

Synopsis

git.merge <repo> [name: value]...

Description

With action: start (the default) the commit named by branch is merged into the current branch. When the current commit is an ancestor of the merged commit, the branch is fast-forwarded: the working tree, the index and the branch move to the merged commit and no commit is created. When the merged commit is already contained in the current branch, nothing changes and the state is up_to_date. Otherwise a three-way merge against the best common ancestor is computed; several best ancestors are first merged into a virtual ancestor. Text is merged line by line with the histogram algorithm, renames are followed according to merge.renames and merge.renameLimit, and the merge and conflict-marker-size attributes are honoured.

A clean three-way merge creates a merge commit whose parents are the current commit and the merged commit. Its message is Merge branch '<name>', Merge remote-tracking branch '<name>', Merge tag '<name>' or Merge commit '<revision>', followed by into <branch> unless the current branch matches merge.suppressDest (by default main and master).

When the merge has conflicts, or when no_commit is true, the merge stops: the working tree holds the merged files with conflict markers, the index holds stages 1, 2 and 3 of each conflicting path, and the state files MERGE_HEAD, MERGE_MSG, MERGE_MODE, AUTO_MERGE and ORIG_HEAD are written in the format of Git, so Git can conclude the merge as well. The call then fails with E_GIT_CONFLICT and effect_applied: true; the effect.git record lists the conflicts.

action: continue concludes a stopped merge with a commit of the index. It requires every conflict to be resolved and staged. The message is the prepared MERGE_MSG without comment lines, or message when given.

action: abort returns the index and the working tree to HEAD for every path the merge changed and removes the merge state files. Local changes of paths that the merge did not touch are kept.

Every check that can refuse a merge runs before the first change: an operation in progress, unresolved paths, staged changes (for a three-way merge), local changes and untracked files in the way of the result. Configured merge drivers (merge.<name>.driver) are not run. The built-in text driver merges the file and the path is reported as filter_not_applied.

Directory renames are applied as with merge.directoryRenames=true: a path added on one side in a directory that the other side renamed is moved to the renamed directory and the merge stays clean. Git, with its default merge.directoryRenames=conflict, performs the same move and additionally reports a file location conflict, leaving the moved path at stage 3 or 2. The merge.directoryRenames setting is not read.

Parameters

Parameter Type Default Description
repo path required Repository or path inside it.
branch text none Branch to merge; required when action is start.
action enum(start|continue|abort) start Start a merge, continue it after resolving conflicts, or abort it.
fast_forward enum(auto|only|never) auto Fast-forward when possible, only fast-forward, or always create a merge commit.
message text none Message of the merge commit.
no_commit bool false Stop before creating the merge commit.

Input and output

Form Input Output
default none effect, git_conflict

Effect

Property Value
Category change
Effect local
Reversibility reversible
Implementation builtin
Reversibility conditions The previous references and the exact previous content of every changed file are kept in the journal.

Examples

Merge the branch topic into the current branch.

git.merge "/home/user/project" branch: "topic"
effect.git state: completed branch: main

Create a merge commit even when the branch could be fast-forwarded, with an own message.

git.merge "/home/user/project" branch: "release/1.4" fast_forward: never message: "Merge release 1.4"

Conclude a merge after the conflicts were resolved and staged.

git.stage "/home/user/project" action: add paths: ["src/main.rs"]
git.merge "/home/user/project" action: continue

Abort a merge that stopped with conflicts.

git.merge "/home/user/project" action: abort

Errors

Code Meaning Typical fix
E_GIT_CONFLICT The merge stopped with conflicts (effect_applied: true), or the index has unresolved paths (unmerged_paths). Resolve the files, stage them and run action: continue, or run action: abort.
E_GIT_DIRTY Staged changes (staged_changes), local changes (local_changes) or untracked files are in the way. Commit or stash the changes: git.stash "<repo>" action: push.
E_GIT_IN_PROGRESS Another operation is in progress, or no merge is stopped for continue and abort (no_merge_in_progress). Conclude or abort the operation in progress.
E_GIT_NON_FAST_FORWARD fast_forward: only and the histories diverged (not_possible), or the histories are unrelated (unrelated_histories). Merge with fast_forward: auto, or rebase onto the branch.
E_GIT_REVISION branch names no commit. Give an existing branch, tag or commit.
E_GIT_LOCKED index.lock or a reference lock exists. Wait for the other Git process or remove the lock file.
E_MISSING_PARAM action: start without branch. Give branch: "<name>".

git.status, git.stage, git.commit, git.rebase, git.pull, git.stash, undo.

Source file on GitHub: docs/commands/git.merge.md