gitbutlerapp/gitbutler · error

push failed

Error message

push failed

What it means

sync_metadata in crates/but-agentlog/src/gitmeta/write.rs pushes GitMeta metadata with push_once. If the push reports failure and the failure is NOT a non-fast-forward condition (which would be retried after conflict resolution), the code cannot classify or fix it and bails with the bare 'push failed'.

Solutions

  1. Run the push manually (git push on the GitMeta ref) to see the underlying rejection reason from the remote.
  2. Check credentials/permissions for the remote (token expiry, SSH key, branch protection rules) and fix them.
  3. Verify network/remote availability, then re-run the operation that triggers sync_metadata.
  4. If it was a transient failure, simply retry — non-fast-forward conflicts are retried automatically but other failures are not.
Defensive patterns

Strategy: retry

Validate before calling

// before triggering sync, check remote reachability and auth
git ls-remote <remote> --heads 2>&1 || panic!("remote unreachable or auth failed before sync")

Try / catch

match sync_metadata(...).context("syncing GitMeta") {
    Ok(_) => (),
    Err(e) if e.to_string() == "push failed" => {
        // inspect the real git push error, fix credentials/branch rules, then retry
        diagnose_push(&gitmeta_remote)?;
        retry_with_backoff(sync_metadata, 3)?;
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling sync_metadata (via run_from_dir) when .push_once(None) returns output.success == false and output.non_fast_forward == false — e.g. remote rejected the push for reasons other than a stale ref.

Common situations: Authentication failure against the remote; protected branch rejecting the push; network/remote outage; remote repository unavailable or quota exceeded; GitMeta ref rules disallowing the update.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


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

Appendix: source

Thrown at crates/but-agentlog/src/gitmeta/write.rs:298

    match gitmeta.pull(None) {
        Ok(_) => {}
        // An empty metadata remote has no ref yet; the push below initializes it.
        Err(git_meta_lib::Error::GitCommand(message))
            if message.contains("couldn't find remote ref") => {}
        Err(err) => return Err(err).context("failed to pull GitMeta metadata"),
    }

    let mut attempts = 0;
    loop {
        attempts += 1;
        let output = gitmeta
            .push_once(None)
            .context("failed to push GitMeta metadata")?;
        if output.success {
            return Ok(());
        }
        if !output.non_fast_forward {
            bail!("push failed");
        }
        if attempts >= MAX_RETRIES {
            bail!("push failed after {MAX_RETRIES} attempts");
        }
        gitmeta
            .resolve_push_conflict(None)
            .context("failed to resolve GitMeta push conflict")?;
    }
}

fn stored_text(kind: RecordKind, text: Option<&str>) -> Option<String> {
    let text = text?;
    Some(match kind {
        RecordKind::ToolResult => redact_text(cap_tool_result_text(text).as_ref()),
        _ => redact_text(text),
    })
}

View on GitHub (pinned to 58e5313667)