gitbutlerapp/gitbutler · error

GitForcePushProtection

GitForcePushProtection

Error message

The force push was blocked because the remote branch contains commits that would be overwritten.\n\n{e}

What it means

Raised when push_with_askpass detects crate::Error::ForcePushProtection: the push would overwrite commits on the remote branch (non-fast-forward). GitButler's force-push protection deliberately blocks it and surfaces this message with code GitForcePushProtection instead of silently rewriting remote history.

Solutions

  1. Fetch and integrate remote commits: pull/rebase your branch onto the remote branch, then push again.
  2. Verify with `git fetch && git log HEAD..origin/<branch>` what would be overwritten.
  3. If overwriting is truly intended, force-push explicitly from the CLI (`git push --force-with-lease`), accepting history loss.
  4. Push to a new branch instead of the diverged remote branch.

Example fix

// before (diverged): push blocked
// after: integrate remote work first
git fetch origin
git rebase origin/my-branch  # or merge
# then retry the push
Defensive patterns

Strategy: try-catch

Validate before calling

// detect divergence before pushing
git fetch origin
const BEHIND = `git rev-list --count HEAD..origin/${branch}`
if (Number(BEHIND) > 0) throw new Error('remote has commits not present locally')

Try / catch

match ctx.push(&branch, "origin", None) {
    Err(e) if e.to_string().contains("force push was blocked") => {
        // prompt user: pull/rebase or confirm explicit force-with-lease
    }
    r => r?,
}

Prevention

When it happens

Trigger: Pushing a branch whose history diverges from (is behind) the remote branch — remote has commits not present locally — and the operation would require a force push; calling push or workspace_branch_and_ancestors_push in that state.

Common situations: A teammate pushed to the same branch while you worked; you rebased/amended locally without pulling; switching machines without fetching; restored an older snapshot from oplog.

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/2e812ac93344efc1. Report an issue: GitHub.

Appendix: source

Thrown at crates/gitbutler-git/src/context.rs:287

    })
    .join()
    .map_err(|panic| {
        let reason = if let Some(message) = panic.downcast_ref::<String>() {
            message.clone()
        } else if let Some(message) = panic.downcast_ref::<&'static str>() {
            (*message).to_owned()
        } else {
            "unknown panic payload".to_owned()
        };

        anyhow!("git push worker thread panicked: {reason}").context(
            but_error::Context::new("git push failed unexpectedly").with_code(Code::Unknown),
        )
    })??;
    match result {
            Ok(stderr) => Ok(stderr),
            Err(err) => match err {
                crate::Error::ForcePushProtection(e) => Err(anyhow!(
                    "The force push was blocked because the remote branch contains commits that would be overwritten.\n\n{e}"
                )
                .context(Code::GitForcePushProtection)),
                crate::Error::GerritNoNewChanges(_) => {
                    // Treat "no new changes" as success for Gerrit.
                    Ok(String::new())
                }
                crate::Error::NonFastForward(_) => Err(err).context(Code::GitNonFastForward),
                _ => Err(map_needs_authorization(err)),
            },
        }
}

fn serialize_branch_to_remote<S>(
    branch_to_remote: &[(String, gix::refs::FullName, String)],
    serializer: S,
) -> std::result::Result<S::Ok, S::Error>
where

View on GitHub (pinned to 58e5313667)