question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't find git in WSL2

See original GitHub issue

describe your issue

Command pre-commit install fails with the following error:

An error has occurred: FatalError: git failed. Is it installed, and are you in a Git repository directory? Check the log at /home/david/.cache/pre-commit/pre-commit.log

I’m executing the command inside of Windows Subsystem for Linux (WSL2) in a git repository that’s inside the linux filesystem. Commands like git --version and git status are working.

pre-commit --version

pre-commit 2.17.0

.pre-commit-config.yaml

- repo: git://github.com/jcchavezs/pre-commit-kotlin
  rev: HEAD
  hooks:
    - id: ktlint
      args:
      - --color --disabled_rules=no-wildcard-imports

~/.cache/pre-commit/pre-commit.log (if present)

version information

pre-commit version: 2.17.0
git --version: [Errno 8] Exec format error: '/usr/local/bin/git'
sys.version:
    3.8.10 (default, Nov 26 2021, 20:14:08)
    [GCC 9.3.0]
sys.executable: /usr/bin/python3
os.name: posix
sys.platform: linux

error information

An error has occurred: FatalError: git failed. Is it installed, and are you in a Git repository directory?
Traceback (most recent call last):
  File "/home/david/.local/lib/python3.8/site-packages/pre_commit/git.py", line 59, in get_root
    cmd_output('git', 'rev-parse', '--show-cdup')[1].strip(),
  File "/home/david/.local/lib/python3.8/site-packages/pre_commit/util.py", line 160, in cmd_output
    returncode, stdout_b, stderr_b = cmd_output_b(*cmd, **kwargs)
  File "/home/david/.local/lib/python3.8/site-packages/pre_commit/util.py", line 154, in cmd_output_b
    raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/usr/local/bin/git', 'rev-parse', '--show-cdup')
return code: 1
expected return code: 0
stdout:
    [Errno 8] Exec format error: '/usr/local/bin/git'

stderr: (none)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/david/.local/lib/python3.8/site-packages/pre_commit/error_handler.py", line 70, in error_handler
    yield
  File "/home/david/.local/lib/python3.8/site-packages/pre_commit/main.py", line 351, in main
    _adjust_args_and_chdir(args)
  File "/home/david/.local/lib/python3.8/site-packages/pre_commit/main.py", line 168, in _adjust_args_and_chdir
    toplevel = git.get_root()
  File "/home/david/.local/lib/python3.8/site-packages/pre_commit/git.py", line 63, in get_root
    raise FatalError(
pre_commit.errors.FatalError: git failed. Is it installed, and are you in a Git repository directory?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
asottilecommented, Feb 24, 2022

you probably forgot #!/bin/sh on that script

0reactions
davidkoppcommented, Feb 24, 2022

Thank you for that hint! Indeed I had placed /usr/local/bin/git there in the first placed with a script. Unfortunately I had forgot about that script. When I remove this script from there the pre-commit install command works. So sorry for the unnecessary interruption.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get started using Git on WSL - Windows
Learn how to set up Git for version control on the Windows Subsystem for Linux, along with Git Credential Manager.
Read more >
Can't find git installed in WSL #255
I have git installed in WSL Ubuntu, but Git Credential Manager ... backed by Windows Credentials Manager, but use git only in WSL...
Read more >
How to get started with Git on Windows and WSL
To get started on Windows, you'll first need to install Git. The installation will include a dedicated Git Bash terminal, but you don't...
Read more >
Setting Up Git on Windows Subsystem for Linux | Tower Blog
Git comes installed with most Linux distributions, but you can make sure you're using the latest stable version by running the following command:...
Read more >
wsl 2 - gitk: "Cannot find a git repository here" when ...
I found the problem. According to this answer, gitk runs git under the hood to determine if it's being run in a git...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found