{"record":{"id":"3676c21d47080871","repo":"windmill-labs/windmill","slug":"you-can-only-create-forks-within-a-git-repo-forks","errorCode":null,"errorMessage":"You can only create forks within a git repo. Forks are tracked with git and synced to your instance with the git sync workflow.","messagePattern":"You can only create forks within a git repo\\. Forks are tracked with git and synced to your instance with the git sync workflow\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/workspace/fork.ts","lineNumber":37,"sourceCode":"  findWorkspaceByGitBranch,\n  getEffectiveGitBranch,\n  getWorkspaceNames,\n  readConfigFile,\n} from \"../../core/conf.ts\";\n\nasync function createWorkspaceFork(\n  opts: GlobalOptions & {\n    createWorkspaceName: string | undefined;\n    color: string | undefined;\n    datatableBehavior: string | undefined;\n    fromBranch: string | undefined;\n    yes: boolean | undefined;\n  },\n  workspaceName: string | undefined,\n  workspaceId: string | undefined = undefined,\n) {\n  if (!isGitRepository()) {\n    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.\");\n  }\n\n  const currentBranch = getCurrentGitBranch()\n  if (!currentBranch) {\n    throw new Error(\"Could not get git branch name\");\n  }\n\n  const config = await readConfigFile({ warnIfMissing: false });\n  const originalBranchIfForked = getOriginalBranchForWorkspaceForks(currentBranch);\n\n  // A \"base branch\" is one we must not rename onto a fork branch: mapped to a\n  // workspace in wmill.yaml, or a conventional default (main/master).\n  const isBaseBranch = (branch: string): boolean =>\n    branch === \"main\" ||\n    branch === \"master\" ||\n    findWorkspaceByGitBranch(config.workspaces, branch) !== undefined;\n\n  // Decide the base branch the fork links to, and whether to rename the","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/cli/src/commands/workspace/fork.ts#L19-L55","documentation":"`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.","triggerScenarios":"Running `wmill workspace fork` from a directory that is not a git working tree or repository (no .git found by git rev-parse).","commonSituations":"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.","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"],"exampleFix":"// before (wrong directory)\ncd /tmp/build-output && wmill workspace fork\n// after\ncd ~/my-project  # a git clone\ngit rev-parse --is-inside-work-tree && wmill workspace fork","handlingStrategy":"validation","validationCode":"import { execSync } from 'node:child_process';\nfunction isGitRepository(): boolean {\n  try { execSync('git rev-parse --is-inside-work-tree', { stdio: 'pipe' }); return true; }\n  catch { return false; }\n}\nif (!isGitRepository()) throw new Error('Run `wmill workspace fork` from inside a git repository.');","typeGuard":"function isInGitRepo(cwd: string): boolean {\n  try { execSync('git rev-parse --is-inside-work-tree', { cwd, stdio: 'pipe' }); return true; }\n  catch { return false; }\n}","tryCatchPattern":"try {\n  await createWorkspaceFork(opts, name, id);\n} catch (e) {\n  if ((e as Error).message.includes('only create forks within a git repo')) {\n    console.error('Not a git repo — clone or `git init` first.');\n    process.exitCode = 1;\n  } else throw e;\n}","preventionTips":["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"],"tags":["git","cli","workspace-fork"],"backgroundTag":"not-a-git-repository","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}