How to solve “Unable to find git in your PATH” on Flutter?

If you’re a developer who’s been working with Flutter, chances are that you’ve encountered an issue where the ‘git’ command couldn’t be found in your system’s PATH. This can be frustrating, especially when trying to run commands like `flutter doctor` or `flutter pub get`. In this blog post, we’ll explore how to solve this problem and get back to coding with Flutter.

The Problem

When you try to run a command that relies on the ‘git’ executable being in your system’s PATH (like `flutter doctor`), you might see an error message like “Unable to find git in your PATH”. This can happen for several reasons, such as:

  • The git executable is not installed or properly configured.
  • There are issues with the environment variables that define your system’s PATH.
  • Conflicting settings on your machine.

My Solution (for Windows 11 64-bit, Flutter 3.7.3, installed via Chocolatey)

The solution to this problem is quite simple and relates to the security settings of Git that can detect dubious ownership for the Flutter repository. To fix this issue, you need to add the Flutter base directory to the Git directory exception list.

git config --global --add safe.directory C:/tools/flutter-base-dir

Alternatively, you can change the ownership of the Flutter base directory using the `fix-unsafe-repository` command:

If That Doesn’t Work…

If the solutions listed above don’t work for you, try adding a wildcard exception to your Git settings. This is the only solution that works for me according to this GitHub issue: https://github.com/flutter/flutter/issues/123995.

git config --global --add safe.directory '*'

This will allow Git to ignore any potential security issues with the Flutter repository, and you should be able to run commands like `flutter doctor` without encountering the “Unable to find git in your PATH” error.