{"record":{"id":"948c41d05b1aa13e","repo":"mislav/hub","slug":"create-must-be-run-from-inside-a-git-repository","errorCode":null,"errorMessage":"'create' must be run from inside a git repository","messagePattern":"'create' must be run from inside a git repository","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/create.go","lineNumber":66,"sourceCode":"\n\t\t$ hub create sinatra/recipes\n\t\t[ repo created in GitHub organization ]\n\t\t> git remote add -f origin git@github.com:sinatra/recipes.git\n\n## See also:\n\nhub-init(1), hub(1)\n`,\n}\n\nfunc init() {\n\tCmdRunner.Use(cmdCreate)\n}\n\nfunc create(command *Command, args *Args) {\n\t_, err := git.Dir()\n\tif err != nil {\n\t\terr = fmt.Errorf(\"'create' must be run from inside a git repository\")\n\t\tutils.Check(err)\n\t}\n\n\tvar newRepoName string\n\tif args.IsParamsEmpty() {\n\t\tdirName, err := git.WorkdirName()\n\t\tutils.Check(err)\n\t\tnewRepoName = github.SanitizeProjectName(dirName)\n\t} else {\n\t\tnewRepoName = args.FirstParam()\n\t\tif newRepoName == \"\" {\n\t\t\tutils.Check(command.UsageError(\"\"))\n\t\t}\n\t}\n\n\tconfig := github.CurrentConfig()\n\thost, err := config.DefaultHost()\n\tif err != nil {","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/mislav/hub/blob/5c547ed804368763064e51f3990851e267e88edd/commands/create.go#L48-L84","documentation":"In commands/create.go create, the command starts by calling git.Dir(); if that fails, the working directory is not inside a git repository. Because creating a repo defaults to using the current directory as the project name/source, the command aborts with \"'create' must be run from inside a git repository\".","triggerScenarios":"Running `hub create` in a plain directory (no .git), in a subdirectory of a non-repo, or with a broken GIT_DIR so git.Dir() returns an error.","commonSituations":"Setting up a new project and running `hub create` before `git init`; running the command in a home or temp directory; GIT_DIR pointing to a missing path in the environment.","solutions":["Initialize a repo first: `git init && git add -A && git commit -m \"initial\"`, then `hub create`.","Change into the existing project directory that is already a git repo.","Or pass an explicit name if your hub version supports it, e.g. `hub create user/newrepo`, avoiding workdir deduction.","Check env (GIT_DIR) is not pointing to an invalid location."],"exampleFix":"// before\n~/newproject$ hub create   // 'create' must be run from inside a git repository\n// after\n~/newproject$ git init\n~/newproject$ hub create","handlingStrategy":"validation","validationCode":"# only run hub create inside a git repo\ngit rev-parse --is-inside-work-tree >/dev/null 2>&1 || \\\n  { echo \"run 'git init' first\"; exit 1; }","typeGuard":null,"tryCatchPattern":"if _, err := git.Dir(); err != nil {\n    return fmt.Errorf(\"cd into a git repository (or git init) before 'create'\")\n}","preventionTips":["Always `git init` + initial commit before `hub create` in a new project","Check `git rev-parse --is-inside-work-tree` in wrappers around hub","Avoid running hub create from home/tmp directories","Don't override GIT_DIR to a nonexistent path"],"tags":["git","cli","repository","environment"],"backgroundTag":"not-a-git-repository","analyzedSha":"5c547ed804368763064e51f3990851e267e88edd","analyzedAt":"2026-09-01T03:34:15.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}