sds/overcommit · error · Overcommit::Exceptions::InvalidGitRepo

does not appear to be a git repository

Error message

does not appear to be a git repository

What it means

After confirming the target is a directory, Installer runs 'git rev-parse --git-dir' inside it; if git exits non-zero there is no repository metadata, so it raises InvalidGitRepo 'does not appear to be a git repository'. Overcommit stores hooks and signatures under .git, so a valid repository is mandatory.

Source

Thrown at lib/overcommit/installer.rb:97

    end

    def ensure_directory(path)
      FileUtils.mkdir_p(path)
    end

    def validate_target
      absolute_target = File.expand_path(@target)

      unless File.directory?(absolute_target)
        raise Overcommit::Exceptions::InvalidGitRepo, 'is not a directory'
      end

      git_dir_check = Dir.chdir(absolute_target) do
        Overcommit::Utils.execute(%w[git rev-parse --git-dir])
      end

      unless git_dir_check.success?
        raise Overcommit::Exceptions::InvalidGitRepo, 'does not appear to be a git repository'
      end
    end

    def install_master_hook
      FileUtils.mkdir_p(hooks_path)
      FileUtils.cp(MASTER_HOOK, master_hook_install_path)
    end

    def uninstall_master_hook
      FileUtils.rm_rf(master_hook_install_path, secure: true)
    end

    def install_hook_files
      # Copy each hook type (pre-commit, commit-msg, etc.) from the master hook.
      Dir.chdir(hooks_path) do
        Overcommit::Utils.supported_hook_types.each do |hook_type|
          unless can_replace_file?(hook_type)
            raise Overcommit::Exceptions::PreExistingHooks,

View on GitHub (pinned to fee0cd74b2)

Solutions

  1. Initialize the repository first: 'git init <dir>' then 'overcommit --install <dir>'
  2. If .git exists but is broken, verify with 'git status' and repair or re-clone before installing hooks
  3. Check 'env | grep ^GIT_' - unset stale GIT_DIR/GIT_WORK_TREE values and retry

Example fix

# before
$ overcommit --install .
does not appear to be a git repository

# after
$ git init
$ overcommit --install .
Defensive patterns

Strategy: validation

Validate before calling

def git_repo?(dir)
  system('git', '-C', dir, 'rev-parse', '--git-dir', out: File::NULL, err: File::NULL)
end

abort 'Not a git repository - run git init first' unless git_repo?(target)

Type guard

def git_repo?(dir)
  Dir.chdir(dir) { system('git', 'rev-parse', '--git-dir', out: File::NULL, err: File::NULL) }
end

Try / catch

begin
  installer.run(target, action: :install)
rescue Overcommit::Exceptions::InvalidGitRepo => e
  abort "#{target}: #{e.message} - run 'git init' first"
end

Prevention

When it happens

Trigger: 'overcommit --install <dir>' on a directory never initialized with 'git init'; a repo whose .git was deleted or corrupted; a directory where GIT_DIR/GIT_WORK_TREE environment variables point somewhere invalid.

Common situations: New project where git init was forgotten; extracted source archive shipped without .git; partially deleted .git directory; CI job cloning into a custom path with broken GIT_* env.

Related errors


AI-assisted analysis of sds/overcommit@fee0cd74b2 (2026-08-23). Data as JSON: /api/errors/a17049b27cff77d3. Report an issue: GitHub.