gitbutlerapp/gitbutler · error
failed to find branch
Error message
failed to find branch {target_branch_refname} What it means
Thrown in git_test_push when the remote-tracking ref `refs/remotes/<remote>/<branch>` cannot be found in the repository. The code looks up the ref to obtain its commit for the test push; a missing ref means the remote branch does not exist locally as a tracking ref.
Solutions
- Run `git fetch <remote_name>` to populate the remote-tracking ref first.
- Verify remote_name and branch_name are correct (`git branch -r`).
- If the remote branch was deleted upstream, prune stale refs (`git fetch --prune`) and choose an existing branch.
- Ensure the ref exists before calling: try_find_reference and handle None.
Example fix
// before
ctx.git_test_push("origin", "feature")?; // ref missing
// after
ctx.fetch("origin", None)?;
ctx.git_test_push("origin", "feature")?; Defensive patterns
Strategy: validation
Validate before calling
let tracking = format!("refs/remotes/{remote}/{branch}");
if repo.try_find_reference(&tracking)?.is_none() {
// fetch first or surface a clear message
ctx.fetch(remote, None)?;
} Prevention
- Fetch the remote before any push-test logic that reads tracking refs.
- Verify branch exists on remote with `git ls-remote <remote> <branch>`.
- Use git fetch --prune to keep tracking refs truthful.
When it happens
Trigger: Calling git_test_push for a remote/branch pair where `refs/remotes/<remote_name>/<branch_name>` does not exist locally — the remote branch was never fetched, was deleted upstream, or remote/branch names are misspelled.
Common situations: Testing a push to a branch that was force-deleted on the remote; shallow or fresh clone without `git fetch`; typo in remote_name or branch_name; remote-tracking refs pruned.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Branch ' ' not found
- Branch ' ' not found when checking for conflicts
- Cannot apply non-existing branch
- Cannot unapply non-existing branch
- Local branch ' ' not found
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/78ac437eb11830a0.
Report an issue: GitHub.
Appendix: source
Thrown at crates/gitbutler-git/src/context.rs:106
force_push_protection,
refspec,
askpass_broker,
push_opts,
)
}
fn git_test_push(
&self,
remote_name: &str,
branch_name: &str,
askpass: Option<Option<StackId>>,
) -> Result<()> {
let target_branch_refname: gix::refs::FullName =
format!("refs/remotes/{remote_name}/{branch_name}").try_into()?;
let repo = self.repo.get()?;
let mut branch = repo
.try_find_reference(&target_branch_refname.to_string())?
.ok_or(anyhow!("failed to find branch {target_branch_refname}"))?;
let commit_id = branch.peel_to_commit()?.id;
let branch_name = format!("test-push-{}", now_ms());
let refname: gix::refs::FullName =
format!("refs/remotes/{remote_name}/{branch_name}").try_into()?;
self.push(
commit_id,
refname.clone(),
false,
false,
None,
askpass,
vec![],
)
.map_err(|err| anyhow!(err.to_string()))?;
let empty_refspec = Some(format!(":refs/heads/{branch_name}"));View on GitHub (pinned to 58e5313667)