{"record":{"id":"2e812ac93344efc1","repo":"gitbutlerapp/gitbutler","slug":"gitforcepushprotection","errorCode":"GitForcePushProtection","errorMessage":"The force push was blocked because the remote branch contains commits that would be overwritten.\\n\\n{e}","messagePattern":"The force push was blocked because the remote branch contains commits that would be overwritten\\.\\\\n\\\\n(.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gitbutler-git/src/context.rs","lineNumber":287,"sourceCode":"    })\n    .join()\n    .map_err(|panic| {\n        let reason = if let Some(message) = panic.downcast_ref::<String>() {\n            message.clone()\n        } else if let Some(message) = panic.downcast_ref::<&'static str>() {\n            (*message).to_owned()\n        } else {\n            \"unknown panic payload\".to_owned()\n        };\n\n        anyhow!(\"git push worker thread panicked: {reason}\").context(\n            but_error::Context::new(\"git push failed unexpectedly\").with_code(Code::Unknown),\n        )\n    })??;\n    match result {\n            Ok(stderr) => Ok(stderr),\n            Err(err) => match err {\n                crate::Error::ForcePushProtection(e) => Err(anyhow!(\n                    \"The force push was blocked because the remote branch contains commits that would be overwritten.\\n\\n{e}\"\n                )\n                .context(Code::GitForcePushProtection)),\n                crate::Error::GerritNoNewChanges(_) => {\n                    // Treat \"no new changes\" as success for Gerrit.\n                    Ok(String::new())\n                }\n                crate::Error::NonFastForward(_) => Err(err).context(Code::GitNonFastForward),\n                _ => Err(map_needs_authorization(err)),\n            },\n        }\n}\n\nfn serialize_branch_to_remote<S>(\n    branch_to_remote: &[(String, gix::refs::FullName, String)],\n    serializer: S,\n) -> std::result::Result<S::Ok, S::Error>\nwhere","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/gitbutler-git/src/context.rs#L269-L305","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Fetch and integrate remote commits: pull/rebase your branch onto the remote branch, then push again.","Verify with `git fetch && git log HEAD..origin/<branch>` what would be overwritten.","If overwriting is truly intended, force-push explicitly from the CLI (`git push --force-with-lease`), accepting history loss.","Push to a new branch instead of the diverged remote branch."],"exampleFix":"// before (diverged): push blocked\n// after: integrate remote work first\ngit fetch origin\ngit rebase origin/my-branch  # or merge\n# then retry the push","handlingStrategy":"try-catch","validationCode":"// detect divergence before pushing\ngit fetch origin\nconst BEHIND = `git rev-list --count HEAD..origin/${branch}`\nif (Number(BEHIND) > 0) throw new Error('remote has commits not present locally')","typeGuard":null,"tryCatchPattern":"match ctx.push(&branch, \"origin\", None) {\n    Err(e) if e.to_string().contains(\"force push was blocked\") => {\n        // prompt user: pull/rebase or confirm explicit force-with-lease\n    }\n    r => r?,\n}","preventionTips":["Fetch before pushing and rebase on the remote branch when behind.","Prefer --force-with-lease semantics when force is intentional.","Avoid amending/rebasing shared branches without integrating remote changes first."],"tags":["git","push","force-push","non-fast-forward"],"backgroundTag":"git-command-failed","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}