gitbutlerapp/gitbutler · error · Error

No branch selected!

Error message

No branch selected!

What it means

In CommitView.svelte, saveCommitMessage throws Error("No branch selected!") when the derived `branchName` (from the currently selected stack/branch state) is undefined while saving an edited commit message. The component cannot determine which branch the commit belongs to, so updating via stackService.updateCommitMessage would be unsafe.

Solutions

  1. Re-select the stack/branch in the UI before editing the commit message
  2. Close and reopen the commit message editor so it re-derives branchName from fresh selection state
  3. Guard the edit entry point: disable the edit mode if branchName is undefined instead of throwing on save
  4. Refresh project/stack state (rebase/undo may have invalidated the previous selection)

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: "Select a branch before editing this commit", style: "danger" });
    setMode("view");
    return;
  }
Defensive patterns

Strategy: type-guard

Validate before calling

const branchName = selected.current?.branchName;
if (!branchName) {
  showToast({ message: 'Select a branch first', style: 'danger' });
  return;
}
await saveCommitMessage(title, description);

Type guard

function canEditCommit(state: { branchName?: string }): state is { branchName: string } {
  return typeof state.branchName === 'string' && state.branchName.length > 0;
}

Try / catch

try {
  await saveCommitMessage(title, description);
} catch (e) {
  if (e instanceof Error && e.message === 'No branch selected!') {
    showToast({ message: 'No branch selected — select a branch and retry', style: 'danger' });
    setMode('view');
  } else { throw e; }
}

Prevention

When it happens

Trigger: Editing and saving a commit message while no branch is currently selected — e.g. selection state was cleared, the stack/branch was deleted or rebased mid-edit, or the component rendered outside a valid lane selection so selected.current?.branchName is undefined.

Common situations: User deletes/renames the branch while the commit-message editor is open; stale UI state after a background rebase or undo; selection reset by another exclusive action; component mounted with missing lane state.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/612cc4a72b480b0b. Report an issue: GitHub.

Appendix: 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 58e5313667)