111

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?

2
  • 1
    I deleted the .gradle file and it worked well. Actually, it reduces the indexing time also. Commented Jul 3, 2022 at 17:42
  • 4
    For Windows, I've realised it's something to do with Admin account vs. regular. Running flutter doctor -v in Admin mode works, in regular mode does not. Commented Apr 2, 2023 at 21:37

25 Answers 25

114

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

Sign up to request clarification or add additional context in comments.

9 Comments

Didnt work. I already installed git.
This didn't work for me in Windows sadly. The only think I have worked out is that it work if you are in terminal/powershell in Admin mode, but not as a regular user.
flutter really should clarify their error message for this one. I would never have guessed this was the issue looking at the error message
For people trying this on Windows make sure you use forward slashes in the path, backslashes do not work. And if you're using FVM don't use the symbolic link, use the actual physical path. Took me an hour to figure that out.
there is no flutter base directory in my case only tools/dart-sdk
|
94

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

1 Comment

Probably not a good idea to use '*' here - you're bypassing a security measure which is there for a reason. You should only need to add the directory where Flutter is located. If that doesn't work note that on Windows you MUST use forward slashes in the path, not backslashes. Also, if you're using FVM, use the real path, not the FVM symbolic link. (eg git config --global --add safe.directory 'C:/Users/james/fvm/versions/3.10.6')
44

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 ;

2 Comments

This has really helped out after a week, thanks
No need to include git.exe. Only C:\Program Files\Git\bin will do.
33

Install it using following command.

sudo apt-get install git

Comments

29

I had the same problem on Windows 10. I've tried everything but running cmd as Administrator solved my problem.

Comments

10

just add C:\Windows\System32 to your system variable PATH. it works

Comments

9

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!

2 Comments

For me this is the best answer as you dont give permission to all folders in the computer
The "" is important I guess, not sure why.
8

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 *

Comments

6

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.

Comments

4

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)

  1. C:\src\flutter\bin
  2. C:\Windows\System32
  3. C:\Windows\System32\WindowsPowerShell\v1.0
  4. C:\Program Files\Git\bin\git.exe
  5. C:\Program Files\Git\cmd

Alternative: Try use windows PowerShell (admin), it work for me

1 Comment

on my side i have tried adjusting the settings.json by adding path to the terminal.profile ""PATH": "C:\\Program Files\\Git\\bin;C:\\Program Files\\Git\\cmd;${env:PATH}"" this adds the path of both the cmd and git to the setting on the vscode where by; you can access through "Ctrl + Shift + P" then type the "Preferences: Open Settings (JSON)" this worked for me i thinky it may work for you am using "Windows"
4

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:

  • Go to Registry Editor. You can find it in Windows search or by pressing "Windows key" + R. Type in "regedit" and it will open.
  • After that, got to "Computer\HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor", find AutoRun key and delete it.
  • If there is no AutoRun key, it might be located in "HKEY_CURRENT_USER" instead of "HKEY_LOCAL_MACHINE".

Really strange error but this was causing flutter to sometimes look in folder specified at this key instead of current folder.

Comments

3

Install Git and run the below command git config --global --add safe.directory C:/tools/flutter-base-dir

4 Comments

If this does not work, you can try this one git config --global --add safe.directory '*' Actually this is the only solution which works for me github.com/flutter/flutter/issues/123995
Thank you Terry you saved me, none of the answers did
By the way I don't have any C:/tools/flutter-base-dir , My flutter lives in F:\ProgTools\flutterLatest\flutter yet "git config --global --add safe.directory F:\ProgTools\flutterLatest\flutter" didn't work So I tried what you said and it worked
This is the only solution that worked for me: git config --global --add safe.directory C:/dev/flutter-sdk/flutter
2

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.

Comments

2

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. enter image description here

Comments

1

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.

Comments

1

If you are running from an IDE like Android Studio, you might try running the equivalent command on the terminal:

flutter.bat pub get

Comments

1

here is what works for me open cmd with admin privilege then type:

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

Comments

1

For me fixed by stop running Android Studio as administrator.

Comments

0

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.

Comments

0

In my case adding entries to environment variable doesn't work but the following has worked for me.

  1. Click start
  2. Search for Git CMD (assumed that Git is installed)
  3. Right click on Git CMD and select "Run as administrator"
  4. Run the command whatever you want (in my case I was trying to run dart pub global activate flutterfire_cli command to configure firebase with my flutter project).

I hope it will help someone.

Comments

0

In my case for VS Code, it turned out that the flutter was out of date, what I did was first close the VS Code

Then ran cmd as an administrator by searching for cmd in the Windows search and right-clicking on the command Prompt search result.

Upon opening the command prompt as an administrator, type this on your keyboard:

Flutter Upgrade

Flutter will upgrade both your flutter and dart to the latest versions.

Also, make sure you have installed the latest version of git and add the environment variable in the system environment variables on your Windows settings.

Finally, run the VS Code as an administrator

Comments

0

I have a slightly odd solution, but it worked for me:

  • uninstall Flutter completely
  • download the Flutter extension in VSCode (I think you have it), then the extension will prompt you that the SDK is not found and offer to download it. You just click on “Download SDK” and you're done!

Comments

0

I had the same issue. I had changed my Windows and wanted to use the SDK folder from the previous Windows installation. The problem was resolved for me when I deleted the Flutter SDK folder and replaced it with a new SDK

Comments

0

Had the same issue after cloning my Flutter app for git. In order to resolve I had to open VS Code as admin. Saw that I had an outdated Dart SDK version and had to run flutter upgrade. Hope it helps :)

Comments

0

My problem is solved by downloading the SDK instead of pulling from git.

Looks like git-pulled SDK has this issue some times.

Here is the pointer:

https://github.com/flutter/flutter/issues/122984#issuecomment-1483738042

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.