I've just tried to install Flutter on Linux and when I try to run a flutter command (flutter doctor), I'm getting
Error: Unable to find git in your PATH.
How can I solve this?
I've just tried to install Flutter on Linux and when I try to run a flutter command (flutter doctor), I'm getting
Error: Unable to find git in your PATH.
How can I solve this?
Add
C:\Program Files\Git\bin\git.exe;C:\Program Files\Git\cmd;C:\Windows\System32
to your PATH variable
Do not create new variable for git but add them as I did one after another separating them by ;
Here is my solution for Windows 11 64bit, flutter 3.7.3, installed via chocolatey. It has simply to do with enforced git security settings which can detect dubious ownship for the flutter repository. Just add the flutter base directory to the git directory exception list:
git config --global --add safe.directory C:/tools/flutter-base-dir
or change the ownership of the flutter base directory with fix unsafe git repository
Install it using following command.
sudo apt-get install git
If solutions listed do not work for you, try this one
git config --global --add safe.directory '*'
This is the only solution which works for me github.com/flutter/flutter/issues/123995
I had the same problem on Windows 10. I've tried everything but running cmd as Administrator solved my problem.
just add C:\Windows\System32
to your system variable PATH.
it works
I also got the same problem because my system didn't had git installed. So I downloaded git from https://git-scm.com/downloads and installed it and just after installing, it worked.
If nothing above helps, this might be a possible solution. Note, this is for Windows.
To me nothing seemed to work so I ended up digging up flutter batch files. The error is located at %FLUTTER_ROOT%\bin\internal\shared.bat. This is how this line of code looks like:
REM Check that git exists and get the revision
SET git_exists=false
2>NUL (
PUSHD "%flutter_root%"
FOR /f %%r IN ('git rev-parse HEAD') DO (
SET git_exists=true
SET revision=%%r
)
POPD
)
REM If git didn't execute we don't have git. Exit without /B to avoid retrying.
if %git_exists% == false echo Error: Unable to find git in your PATH. && EXIT 1
This line "2>NUL (" tells windows batch file to not display any internal errors. You can comment it out like this: (Don't forget the closing bracket)
REM 2>NUL (
PUSHD "%flutter_root%"
FOR /f %%r IN ('git rev-parse HEAD') DO (
SET git_exists=true
SET revision=%%r
)
POPD
REM )
After saving that and running flutter command again I got this error: "Fatal: Not A Git Repository". This didn't make any sense since it had .git directory and running "git rev-parse HEAD" in root worked fine.
Reason why this is happening might be because terminal isn't really pointing to current folder and instead it points to something completely else. To me it was "C:\Windows". I figured this part by setting git_exists=true, after that flutter installed without problems. When I tried to run my flutter project, I got error that there is no pubspec.yaml file in my root even though there was. So, tried to test it by creating another flutter project and then I got error that flutter can't create project in "C:\Windows".
So, to fix this, I had to do following:
Really strange error but this was causing flutter to sometimes look in folder specified at this key instead of current folder.
Note: This solution is for Windows only.
Add these variables to Path in environment variable:
(How to add to Path Read: https://stackoverflow.com/a/72341522/8890476)
Alternative: Try use windows PowerShell (admin), it work for me
You can download 64-bit Git for Windows Setup https://git-scm.com/download/win
FOR WINDOWS : If you chose visual studio code during git installation and have multiple user accounts on windows then all you need to do is uninstall git and reinstall git choosing vim as default editor not visual studio code. You also get a warning when choosing visual studio code during git installation. Pay attention to that. For me setting visual studio code as default and having multiple User account was the issue.
Install Git and run the below command git config --global --add safe.directory C:/tools/flutter-base-dir
I was having everything set correctly but I was still facing the error I only had to reopen Android Studio as Administration.. I hope this works for anyone
I have tried more steps not worked , but at last success. You need go ''environment variables'' , then in the ''System variables'' create a new variable name 'git' and set variable value 'C:\Program Files\Git\bin'. Then ok. Close your vscode or all cmd file. Then again open and try flutter doctor you should success surely.
in windows 10 C:\src\flutter\bin C:\Windows\System32 C:\Windows\System32\WindowsPowerShell\v1.0 C:\Program Files\Git\bin\git.exe C:\Program Files\Git\cmd
if it still not worked even after applying the above environment variables then Just run Android Studio as Administrator
I tried the other fix that modified flutter.bat but those did not work for me. Find your shared.bat and manually set the git_exists to true.
C:\tools\flutter\bin\internal\shared.bat
SET git_exists=true
2>NUL (
PUSHD "%flutter_root%"
FOR /f %%r IN ('git rev-parse HEAD') DO (
SET git_exists=true
SET revision=%%r
)
POPD
)
You can set the variable to true or add a SET git_exists=true after the block.
C:\src\flutter\bin;C:\Windows\System32
just add this path