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 theView on GitHub (pinned to e474e8803c)
Solutions
- cd into a git clone of your project before running `wmill workspace fork`
- Initialize a repo with `git init` (and make an initial commit) if the folder is meant to be a repo
- 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
- Always run fork commands from the root of your git clone
- Add `git rev-parse --is-inside-work-tree` as a pre-step in CI scripts
- Avoid running wmill commands from build/export artifact directories
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
- Refusing to rename your current branch \`${currentBranch}\`
- Could not resolve parent workspace. Make sure you are in a g
- Could not get git branch name
- --from-branch is for converting a *different* working branch
- Refusing to rename your current branch \`${currentBranch}\`
AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03).
Data as JSON: /api/errors/3676c21d47080871.
Report an issue: GitHub.