gitbutlerapp/gitbutler · error · Error
No branch selected!
Error message
No branch selected!
What it means
Thrown by saveCommitMessage() in the commit-message editor when the branchName for the commit being amended is falsy. The function needs branchName to address updateCommitMessage({projectId, stackId, commitId, message}); it is a precondition supplied by the surrounding UI state, not by the user input (a missing message gets a toast instead, 'Commit message is required').
Source
Thrown at apps/desktop/src/components/commit/CommitView.svelte:97
}
}
const parsedMessage = $derived(splitMessage(commit.message));
function combineParts(title?: string, description?: string): string {
if (!title) {
return "";
}
if (description) {
return `${title}\n\n${description}`;
}
return title;
}
async function saveCommitMessage(title: string, description: string) {
const commitMessage = combineParts(title, description);
if (!branchName) {
throw new Error("No branch selected!");
}
if (!commitMessage) {
showToast({ message: "Commit message is required", style: "danger" });
return;
}
const newCommitId = await updateCommitMessage({
projectId,
stackId,
commitId: commit.id,
message: commitMessage,
dryRun: false,
});
if (stackId) {
uiState.lane(stackId).selection.set({ branchName, commitId: newCommitId, previewOpen: true });
}
setMode("view");View on GitHub (pinned to caf1f223d3)
Solutions
- Close and reopen the commit view after the branch list has refreshed, then retry the save.
- Verify the stack still exists and still contains this commit (check the stack list in the UI or `but` CLI).
- In code, early-return with a toast when !branchName instead of throwing, so the editor degrades gracefully.
- Recompute branchName from the commit's owning stack when the editor mounts, and disable the save button until it resolves.
Example fix
// before
async function saveCommitMessage(title: string, description: string) {
const commitMessage = combineParts(title, description);
if (!branchName) {
throw new Error("No branch selected!");
}
// ...
}
// after
async function saveCommitMessage(title: string, description: string) {
const commitMessage = combineParts(title, description);
if (!branchName) {
showToast({ message: "The branch for this commit is gone — reload the workspace", style: "danger" });
return;
}
// ...
} Defensive patterns
Strategy: validation
Validate before calling
if (!branchName) {
showToast({ message: "Select a branch before saving the commit message", style: "danger" });
return;
}
await saveCommitMessage(title, description); Type guard
function hasBranchName(b: string | null | undefined): b is string {
return typeof b === "string" && b.trim().length > 0;
} Try / catch
try {
await saveCommitMessage(title, description);
} catch (e) {
if (e instanceof Error && e.message === "No branch selected!") {
showToast({ message: "The branch is gone — reload the workspace", style: "danger" });
} else {
throw e;
}
} Prevention
- Disable the save button in the commit editor until branchName resolves to a non-empty string.
- Re-derive branchName from the commit's owning stack every time the editor opens.
- Invalidate open commit editors when their stack or branch is deleted.
When it happens
Trigger: Saving an edited commit message after the branch the commit belonged to stopped being resolvable: branchName prop/state is undefined or empty because the stack was deleted, the branch was renamed/removed out-of-band, or the panel was opened before workspace data finished loading.
Common situations: Commit panel left open while the underlying virtual branch was deleted or merged elsewhere; project workspace not yet hydrated when the user hits save; a concurrent GitButler session rewrote the stack.
Related errors
- No stack selected!
- No branch selected!
- Please sign in to use GitButler's AI API
- Please provide a valid API key for your selected AI service
- Cannot attempt to open non-existing directory: '{}'
AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20).
Data as JSON: /api/errors/612cc4a72b480b0b.
Report an issue: GitHub.