windmill-labs/windmill · error · Error

You can only create forks within a git repo. Forks are track

Error message

You can only create forks within a git repo. Forks are tracked with git and synced to your instance with the git sync workflow.

What it means

`wmill workspace fork` stores forks as git branches (wm-fork/<base>/<id>) and syncs them via the git sync workflow, so it refuses to run outside a git repository. The CLI checks `isGitRepository()` at the very start of `createWorkspaceFork` and throws immediately if the working directory is not inside a repo. This is a hard precondition: without git there is nowhere to record the fork branch mapping.

Source

Thrown at cli/src/commands/workspace/fork.ts:37

  findWorkspaceByGitBranch,
  getEffectiveGitBranch,
  getWorkspaceNames,
  readConfigFile,
} from "../../core/conf.ts";

async function createWorkspaceFork(
  opts: GlobalOptions & {
    createWorkspaceName: string | undefined;
    color: string | undefined;
    datatableBehavior: string | undefined;
    fromBranch: string | undefined;
    yes: boolean | undefined;
  },
  workspaceName: string | undefined,
  workspaceId: string | undefined = undefined,
) {
  if (!isGitRepository()) {
    throw new Error("You can only create forks within a git repo. Forks are tracked with git and synced to your instance with the git sync workflow.");
  }

  const currentBranch = getCurrentGitBranch()
  if (!currentBranch) {
    throw new Error("Could not get git branch name");
  }

  const config = await readConfigFile({ warnIfMissing: false });
  const originalBranchIfForked = getOriginalBranchForWorkspaceForks(currentBranch);

  // A "base branch" is one we must not rename onto a fork branch: mapped to a
  // workspace in wmill.yaml, or a conventional default (main/master).
  const isBaseBranch = (branch: string): boolean =>
    branch === "main" ||
    branch === "master" ||
    findWorkspaceByGitBranch(config.workspaces, branch) !== undefined;

  // Decide the base branch the fork links to, and whether to rename the

View on GitHub (pinned to e474e8803c)

Solutions

  1. cd into a git clone of your project before running `wmill workspace fork`
  2. Initialize a repo with `git init` (and make an initial commit) if the folder is meant to be a repo
  3. Verify with `git rev-parse --is-inside-work-tree` that the current directory is inside a repo

Example fix

// before (wrong directory)
cd /tmp/build-output && wmill workspace fork
// after
cd ~/my-project  # a git clone
git rev-parse --is-inside-work-tree && wmill workspace fork
Defensive patterns

Strategy: validation

Validate before calling

import { execSync } from 'node:child_process';
function isGitRepository(): boolean {
  try { execSync('git rev-parse --is-inside-work-tree', { stdio: 'pipe' }); return true; }
  catch { return false; }
}
if (!isGitRepository()) throw new Error('Run `wmill workspace fork` from inside a git repository.');

Type guard

function isInGitRepo(cwd: string): boolean {
  try { execSync('git rev-parse --is-inside-work-tree', { cwd, stdio: 'pipe' }); return true; }
  catch { return false; }
}

Try / catch

try {
  await createWorkspaceFork(opts, name, id);
} catch (e) {
  if ((e as Error).message.includes('only create forks within a git repo')) {
    console.error('Not a git repo — clone or `git init` first.');
    process.exitCode = 1;
  } else throw e;
}

Prevention

When it happens

Trigger: Running `wmill workspace fork` from a directory that is not a git working tree or repository (no .git found by git rev-parse).

Common situations: Running the CLI from a freshly downloaded/extracted folder instead of a git clone; running from a subdirectory outside the repo; running in CI with a shallow artifact copy rather than a git clone; HOME or cwd misconfigured so git cannot detect the repo.

Related errors


AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03). Data as JSON: /api/errors/3676c21d47080871. Report an issue: GitHub.