gitbutlerapp/gitbutler · error
Failed to determine Gerrit target branch
Error message
Failed to determine Gerrit target branch
What it means
This error is thrown by the `gerrit_review_ref` helper in GitButler's legacy push command when the resolved workspace target has no associated ref name. `ResolvedTarget::resolve_with_perm` resolves the destination for the push (typically the base/target branch the stack builds on), and if `ref_name()` returns None there is no way to derive the Gerrit target branch, so the push for Gerrit review cannot proceed.
Solutions
- Verify the workspace target branch is set and exists on the remote (e.g. `but branch list` / check .git/gitbutler workspace target metadata)
- Re-assign the branch to a valid target branch (e.g. `but branch --assign <target>` or re-initialize the workspace on the intended base branch)
- Fetch the remote so the target ref exists locally, then retry the push
- If the repo is not intended for Gerrit, disable Gerrit push mode (e.g. remove push.gerrit review config / use normal push)
Example fix
// before (conceptual CLI misuse) but push --gerrit # workspace has no resolved target ref // after but branch --assign origin/main but push --gerrit
Defensive patterns
Strategy: validation
Validate before calling
// shell: ensure a target ref resolves before pushing
but branch list 2>/dev/null | grep -q . || { echo 'No workspace/target configured'; exit 1; }
git rev-parse --verify --quiet refs/remotes/origin/HEAD || { echo 'No remote target branch'; exit 1; } Prevention
- Always assign branches to a target branch before pushing
- Keep the remote tracking/target branch fetched locally
- Avoid renaming/deleting the workspace target branch
- Check Gerrit push config only in repos that actually use Gerrit
When it happens
Trigger: Running `but push` (via push_single_branch or push_all_branches) in a workspace configured for Gerrit review where the workspace target resolves to a target without a ref name — e.g. an unborn/unset target branch, a target pointing at a symbolic/detached state, or a workspace whose target metadata was not fully initialized.
Common situations: Cloned repository where the upstream tracking/target branch was never set; user deleted or renamed the target branch; workspace metadata from an older GitButler version lacking complete target info; pushing before assigning the branch to a target branch.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- Cannot push branch ' ': the push would include conflicted…
- Gerrit push flags (--wip, --ready, --hashtag/--tag…
- Hashtag cannot be empty
- No target branch is configured and none could be inferred…
- Topic cannot be empty
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/b1bff1b5c2693bd4.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but/src/command/legacy/push.rs:1215
writeln!(
out,
"{} Push succeeded, but review synchronization failed: {}",
t.sym().warning,
t.hint.paint(message)
)?;
}
Ok(())
}
fn gerrit_review_ref(
ctx: &Context,
perm: &RepoShared,
repo: &gix::Repository,
) -> anyhow::Result<String> {
let target_ref_name = workspace_target::ResolvedTarget::resolve_with_perm(ctx, perm)?
.ref_name()
.map(ToOwned::to_owned)
.ok_or_else(|| anyhow::anyhow!("Failed to determine Gerrit target branch"))?;
let remote_names = repo.remote_names();
let target_branch =
but_core::extract_remote_name_and_short_name(target_ref_name.as_ref(), &remote_names)
.map(|(_, short_name)| short_name.to_string())
.unwrap_or_else(|| target_ref_name.shorten().to_string());
Ok(format!("refs/for/{target_branch}"))
}
/// Check if a push of this branch would include any conflicted commits.
/// The push covers the branch and everything beneath it, named by a branch
/// or not, so all of that is checked. Returns an error if conflicted commits
/// are found.
fn check_for_conflicted_commits(ctx: &Context, branch_name: &str) -> anyhow::Result<()> {
let branch = gix::refs::Category::LocalBranch.to_full_name(branch_name)?;
let Some(commits) =
crate::legacy::workspace::push_scope_with_expensive_commit_info(ctx, branch.as_ref())?
else {View on GitHub (pinned to 58e5313667)