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

  1. Close and reopen the commit view after the branch list has refreshed, then retry the save.
  2. Verify the stack still exists and still contains this commit (check the stack list in the UI or `but` CLI).
  3. In code, early-return with a toast when !branchName instead of throwing, so the editor degrades gracefully.
  4. 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

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


AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20). Data as JSON: /api/errors/612cc4a72b480b0b. Report an issue: GitHub.