mislav/hub · error
'create' must be run from inside a git repository
Error message
'create' must be run from inside a git repository
What it means
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".
Source
Thrown at commands/create.go:66
$ hub create sinatra/recipes
[ repo created in GitHub organization ]
> git remote add -f origin git@github.com:sinatra/recipes.git
## See also:
hub-init(1), hub(1)
`,
}
func init() {
CmdRunner.Use(cmdCreate)
}
func create(command *Command, args *Args) {
_, err := git.Dir()
if err != nil {
err = fmt.Errorf("'create' must be run from inside a git repository")
utils.Check(err)
}
var newRepoName string
if args.IsParamsEmpty() {
dirName, err := git.WorkdirName()
utils.Check(err)
newRepoName = github.SanitizeProjectName(dirName)
} else {
newRepoName = args.FirstParam()
if newRepoName == "" {
utils.Check(command.UsageError(""))
}
}
config := github.CurrentConfig()
host, err := config.DefaultHost()
if err != nil {View on GitHub (pinned to 5c547ed804)
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.
Example fix
// before ~/newproject$ hub create // 'create' must be run from inside a git repository // after ~/newproject$ git init ~/newproject$ hub create
Defensive patterns
Strategy: validation
Validate before calling
# only run hub create inside a git repo
git rev-parse --is-inside-work-tree >/dev/null 2>&1 || \
{ echo "run 'git init' first"; exit 1; } Try / catch
if _, err := git.Dir(); err != nil {
return fmt.Errorf("cd into a git repository (or git init) before 'create'")
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Not a git repository (or any of the parent directories): .gi
- Aborted: no revision could be determined from '%s'
- Error: %s/%s doesn't have a wiki
- the current branch '%s' doesn't seem pushed to a remote
- the branch to compare '%s' is the default branch
AI-assisted analysis of mislav/hub@5c547ed804 (2026-09-01).
Data as JSON: /api/errors/948c41d05b1aa13e.
Report an issue: GitHub.