gitbutlerapp/gitbutler · error

Cannot push branch ' ': the push would include conflicted…

Error message

Cannot push branch '{}': the push would include {} conflicted commit{}.
Conflicted commits: {}
Please resolve conflicts before pushing using 'but resolve <commit>'.

What it means

`check_for_conflicted_commits` blocks a push when any commit in the branch being pushed is still in a conflicted state (conflicts stored by GitButler's conflict stack). GitButler intentionally refuses to publish conflicted commits and directs the user to resolve them first with `but resolve <commit>`.

Solutions

  1. Run `but resolve <commit>` for each listed conflicted commit and resolve the conflicts
  2. Check `but status` to find remaining conflicted files/commits and resolve them
  3. Re-run the push after all conflicts are resolved
  4. If scripting, fail early by checking for conflicts before invoking push

Example fix

// before
but push branch-with-conflicts
// error: push would include 1 conflicted commit
// after
but resolve <commit-id>
but push branch-with-conflicts
Defensive patterns

Strategy: validation

Validate before calling

// resolve all conflicts before pushing
but status | grep -i conflict && { echo 'Resolve first: but resolve <commit>'; exit 1; }

Try / catch

if ! but push "$BRANCH" 2>&1; then
  echo "Push blocked - resolve conflicted commits listed above with: but resolve <commit>"
  exit 1
fi

Prevention

When it happens

Trigger: `but push` (push_single_branch_impl) on a branch whose commit range includes one or more commits with unresolved merge conflicts — detected by mapping conflicted commit ids to change ids via the workspace's id map.

Common situations: User pulled/rebased with conflicts, chose to keep working without resolving, then pushes; automated scripts pushing stacks after an apply that left conflicts; forgetting which commits still carry conflict markers.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/9da6ab1663eed68d. Report an issue: GitHub.

Appendix: source

Thrown at crates/but/src/command/legacy/push.rs:1258

        .map(|c| c.id)
        .collect();
    if conflicted.is_empty() {
        return Ok(());
    }
    let repo = ctx.repo.get()?.clone().for_commit_shortening();
    // Only pay for the map when the error actually prints.
    let id_map = crate::IdMap::legacy_new_from_context(ctx).ok();
    let conflicted_commits: Vec<String> = conflicted
        .iter()
        .map(|id| {
            id_map
                .as_ref()
                .and_then(|id_map| id_map.change_id_ref(*id))
                .map(|change_id| change_id.padded_short_id())
                .unwrap_or_else(|| shorten_object_id(&repo, *id))
        })
        .collect();
    Err(anyhow::anyhow!(
        "Cannot push branch '{}': the push would include {} conflicted commit{}.\n\
             Conflicted commits: {}\n\
             Please resolve conflicts before pushing using 'but resolve <commit>'.",
        branch_name,
        conflicted_commits.len(),
        if conflicted_commits.len() == 1 {
            ""
        } else {
            "s"
        },
        conflicted_commits.join(", ")
    ))
}

#[cfg(test)]
mod tests {
    use super::branch_remote_ref_for_display;
    use gitbutler_git::PushResult;

View on GitHub (pinned to 58e5313667)