gitbutlerapp/gitbutler · error

pre-push hook failed

Error message

pre-push hook failed: {}

What it means

Raised in `workspace_branch_and_ancestors_push` (crates/but-workspace/src/legacy/push.rs:101) when a configured pre-push hook (e.g. a Husky hook) exits with failure during a push. The hook's stderr/error text is embedded in the message via `error_data.error`.

Solutions

  1. Read the embedded hook error output and fix whatever the hook is failing on (lint, tests, etc.)
  2. Run the hook command manually (`git push --dry-run` or invoke `.husky/pre-push`) to reproduce
  3. Temporarily bypass with `git push --no-verify` or by disabling husky hooks in the API call if appropriate
  4. Repair or reinstall husky (`npx husky install`) if the hook itself is broken

Example fix

// before
push::workspace_branch_and_ancestors_push(..., run_husky_hooks=true)?;
// after
// fix failing pre-push hook, or opt out:
push::workspace_branch_and_ancestors_push(..., run_husky_hooks=false)?;
Defensive patterns

Strategy: try-catch

Validate before calling

// dry-run push to exercise hooks without updating the remote
let status = std::process::Command::new("git")
    .args(["push", "--dry-run", remote, refspec])
    .status()?;

Try / catch

match push::workspace_branch_and_ancestors_push(..., run_husky_hooks) {
    Err(e) if e.to_string().starts_with("pre-push hook failed") => report_hook_output(&e),
    other => other?,
}

Prevention

When it happens

Trigger: Pushing workspace branches with `run_husky_hooks` enabled while the repository has a pre-push hook (`.husky/pre-push` or git hooks path) that returns a non-zero exit code.

Common situations: Lint/test gates in the pre-push hook failing; hook scripts broken after Node dependency changes; hook failing only on CI-related checks; user pushed with hooks enabled but local state doesn't pass the checks.

Related errors


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

Appendix: source

Thrown at crates/but-workspace/src/legacy/push.rs:101

                })?;
        let before_sha = remote_before_sha(repo, remote_refname.as_ref())?;
        let remote = repo.find_remote(remote_name.as_str())?;
        let remote_url = remote
            .url(gix::remote::Direction::Push)
            .or_else(|| remote.url(gix::remote::Direction::Fetch))
            .with_context(|| format!("Remote named {remote_name} didn't have a URL"))?;

        if run_hooks {
            match hooks::pre_push(
                repo,
                &remote_name,
                &remote_url.to_bstring().to_str_lossy(),
                local_sha.id,
                &RemoteRefname::from_str(&remote_refname.as_bstr().to_str_lossy())?,
                run_husky_hooks,
            )? {
                hooks::HookResult::Success | hooks::HookResult::NotConfigured => Ok(()),
                hooks::HookResult::Failure(error_data) => Err(anyhow::anyhow!(
                    "pre-push hook failed: {}",
                    error_data.error
                )),
            }?;
        }

        let gerrit_push_args = gerrit_push_args(
            gerrit_mode,
            local_sha.id,
            target_branch_name.as_bstr(),
            &push_opts,
        );
        let push_output = push_with_askpass(
            repo,
            local_sha.id,
            remote_refname.as_ref(),
            with_force,
            force_push_protection && !skip_force_push_protection,

View on GitHub (pinned to 58e5313667)