If you face this issue where you get the error “Unable to find git in your PATH” while running flutter commands like flutter doctor or flutter pub get then here’s the fix for it.
This happens because of a security update from git where Git now checks for ownership of the folder trying to ensure that the folder you are using Git in has the same user as the owner as your current user account.
Git considers all repos as unsafe be default on Windows because of this security update. You can read more about it here – Git Security Issue: CVE-2022-24765
To fix this, we need to mark our repos as safe using the following command:
git config --global --add safe.directory '*'
Restart your terminals and VS Code after running this command. This should fix the issue
If you don’t want to mark all the repos as safe, then you can mark only the flutter repo as safe by passing the flutter path instead of *
git config --global --add safe.directory C:\Users\someUser\flutter\.git\
Conclusion
The above fix will work if you have git installed along with it added to PATH environment variable.
If you don’t have git installed, then install it and make sure that the git folder’s path is mentioned in the PATH environment variable.