Can't find git in WSL2
See original GitHub issuedescribe 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:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
you probably forgot
#!/bin/sh
on that scriptThank 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 thepre-commit install
command works. So sorry for the unnecessary interruption.