windmill-labs/windmill · error
git branch -m ${newName} failed (exit ${r.status}): ${r.stde
Error message
git branch -m ${newName} failed (exit ${r.status}): ${r.stderr ?? ""} What it means
renameCurrentGitBranch runs `git branch -m <newName>` via spawnSync to rename the current branch in place (used by `wmill workspace fork --from-branch` to turn the working branch into a wm-fork/<base>/<id> branch). If git exits non-zero, the helper throws this error including the exit code and git's stderr. It means git itself refused the rename; no fork branch was created.
Source
Thrown at cli/src/utils/git.ts:44
"git",
["show-ref", "--verify", "--quiet", `refs/heads/${branchName}`],
{ stdio: "pipe" },
);
return r.status === 0;
}
/**
* Rename the currently checked-out branch (`git branch -m <newName>`). Used by
* `wmill workspace fork --from-branch` to turn an existing working branch into
* the `wm-fork/<base>/<id>` fork branch in place, preserving its commits.
*/
export function renameCurrentGitBranch(newName: string): void {
const r = spawnSync("git", ["branch", "-m", newName], {
encoding: "utf8",
stdio: "pipe",
});
if ((r.status ?? 1) !== 0) {
throw new Error(
`git branch -m ${newName} failed (exit ${r.status}): ${r.stderr ?? ""}`,
);
}
}
export function getOriginalBranchForWorkspaceForks(branchName: string | null): string | null {
if (!branchName || !branchName.startsWith(WM_FORK_PREFIX)) {
return null
}
const start = branchName.indexOf("/") + 1;
const end = branchName.lastIndexOf("/");
if (start < 0 || end < 0 || end - start <= 0) {
return null
}
return branchName.slice(start, end)View on GitHub (pinned to e474e8803c)
Solutions
- Run the command from inside a git working tree (`git rev-parse --is-inside-work-tree` to confirm).
- Check the stderr in the message for git's specific complaint and fix it (e.g. invalid characters in the generated branch name).
- Commit or stash if git state blocks the rename, then retry `wmill workspace fork`.
- Verify the target branch name is valid: `git check-ref-format --branch <newName>`.
- Ensure git is installed and on PATH.
Example fix
// before: run outside a repo $ cd /tmp && wmill workspace fork --from-branch // Error: git branch -m wm-fork/main/abc failed (exit 128): fatal: not a git repository // after $ cd ~/my-project && wmill workspace fork --from-branch
Defensive patterns
Strategy: try-catch
Validate before calling
import { spawnSync } from "node:child_process";
function canRenameBranchHere(): { ok: boolean; reason?: string } {
const inRepo = spawnSync("git", ["rev-parse", "--is-inside-work-tree"], { encoding: "utf8" });
if (inRepo.status !== 0 || inRepo.stdout?.trim() !== "true") return { ok: false, reason: "not inside a git work tree" };
return { ok: true };
} Type guard
function isBranchNameValid(name: string): boolean {
const r = spawnSync("git", ["check-ref-format", "--branch", name], { stdio: "pipe" });
return r.status === 0;
} Try / catch
try {
renameCurrentGitBranch(newName);
} catch (e) {
if (String(e).includes("git branch -m")) {
console.error(`Branch rename refused: ${e.message}. Are you inside a git repo and is '${newName}' a valid branch name?`);
}
throw e;
} Prevention
- Always run fork commands from inside a git working tree.
- Validate generated fork branch names with `git check-ref-format --branch` before renaming.
- Keep the workspace/fork id free of characters git forbids in branch names.
- Run `git status` first to ensure a sane repo state (not detached HEAD without a branch to rename).
When it happens
Trigger: Calling createWorkspaceFork/renameCurrentGitBranch outside a git repository (exit 128, 'not a git repository'), when newName is empty/invalid as a branch name (exit 128, 'fatal: not a valid branch name'), or any other git-level refusal of `branch -m`.
Common situations: Running `wmill workspace fork` outside a git repo or in a bare checkout; a workspace/fork id that produces an invalid branch name (spaces, invalid chars); detached HEAD or unusual git state; git not installed is not this error (that would surface as r.error instead).
Understand the failure class
Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.
Related errors
- You can only create forks within a git repo. Forks are track
- Could not get git branch name
- --from-branch is for converting a *different* working branch
- Refusing to rename your current branch \`${currentBranch}\`
- Refusing to rename your current branch \`${currentBranch}\`
AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03).
Data as JSON: /api/errors/8d3ffcaa99271e9d.
Report an issue: GitHub.