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?
Install it using following command.
sudo apt-get install git
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
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
git config --global --add safe.directory 'C:/Users/james/fvm/versions/3.10.6'
) –
Piatt 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 ;
Install it using following command.
sudo apt-get install git
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 you use Windows , you must run cmd ( or any terminal ) with "Run As Administrator" and then exec this command :
git config --global --add safe.directory *
Note: This solution is for Windows only.
Add these variables to Path in environment variable:
(How to add to Path Read: https://mcmap.net/q/12998/-adding-a-directory-to-the-path-environment-variable-in-windows)
Alternative: Try use windows PowerShell (admin), it work for me
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.
Uninstall and reinstall GIT solved my problem.
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 tried for a LONG time to get this working.
git config --global --add safe.directory d:/flutter-sdk/flutter
didn't work and I didn't want to use
git config --global --add safe.directory "*"
as I thought it might present a security risk.
Eventually, this worked for me. I
git config --global --add safe.directory "D:/flutter-sdk/flutter"
Note, the "D" drive for me had to be CAPITAL, and I put it in quotes "..."
Hope this helps!
You can download 64-bit Git for Windows Setup https://git-scm.com/download/win
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.
Try to run e.g. git fetch
in flutter directory and check if there is no errors for fetching flutter repository.
In my case it was an error in git global config.
After fixing it everything works fine and i am able to run flutter doctor
.
If you are running from an IDE like Android Studio, you might try running the equivalent command on the terminal:
flutter.bat pub get
if it still not worked even after applying the above environment variables then Just run Android Studio as Administrator
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 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
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
Try installing git from here according to your linux distro https://git-scm.com/download/linux
After trying everything and none worked, I reopen Android Studio as Administration and it worked...
I hope this works for anyone
I Windows you can try re-installing Git using default settings. It should not affect your other apps that use git.
This is my Visual Studio code Terminal:
for this problem my solution is the following: I was trying to make some edits in android studio properties and I gave it the administrator permission when open, so when I open it with administrator permission he just give me this error when I try to start my app:
Error: Unable to find git in your PATH.
I solve it by right click on the android studio from taskbar then right click on android studio again and select properties. now select the "Compatibility" tab from above then unselect "Run this program as an administrator", click Apply then OK.
Now just close Android Studio and reopen it then everything will work :) .
In my case adding entries to environment variable doesn't work but the following has worked for me.
Git CMD
(assumed that Git is installed)Git CMD
and select "Run as administrator"dart pub global activate flutterfire_cli
command to configure firebase with my flutter project).I hope it will help someone.
For visual studio problem: I already set flutter path and flutter command work right in terminal. For me removing flutter plugin and reinstall it fixd the issue in visual studio code. File->Setting->plugin
It worked successfully when I started Android Studio as Administrator
© 2022 - 2024 — McMap. All rights reserved.
flutter doctor -v
in Admin mode works, in regular mode does not. – Photoperiod