54

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?

Nikolay Shindarov
  • 1,616
  • 2
  • 18
  • 25

20 Answers20

36

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 ;

Pika Supports Ukraine
  • 3,612
  • 10
  • 26
  • 42
Marwa Eltayeb
  • 1,921
  • 1
  • 17
  • 29
36

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

Huber Thomas
  • 1,577
  • 1
  • 5
  • 7
  • 2
    This fixes my problem. Been reinstalling git 5 times not including yesterday attempts. Geez! – Yura Mar 05 '23 at 03:21
  • 1
    Didnt work. I already installed git. – chitgoks Mar 18 '23 at 11:47
  • 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. – Badrul Apr 03 '23 at 07:20
  • Thank you! Please know your solution saved my sanity 3 years after you posted it. – Racso Apr 17 '23 at 03:32
  • flutter really should clarify their error message for this one. I would never have guessed this was the issue looking at the error message – xrayian Jul 08 '23 at 11:20
  • 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. – James Allen Jul 23 '23 at 12:35
33

Install it using following command.

sudo apt-get install git
desertnaut
  • 57,590
  • 26
  • 140
  • 166
Marlon Abeykoon
  • 11,927
  • 4
  • 54
  • 75
28

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

Terry Deng
  • 401
  • 7
  • 16
  • 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'`) – James Allen Jul 23 '23 at 12:23
17

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

Furkan Öztürk
  • 1,178
  • 11
  • 24
10

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

Mt Khalifa
  • 459
  • 1
  • 6
  • 20
5

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.

Kunal Verma
  • 51
  • 1
  • 1
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.

3

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

Aathil Ahamed
  • 460
  • 4
  • 16
udin coy
  • 31
  • 2
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 26 '21 at 16:31
  • The correct windows answer is more to do with needing to be in admin mode not about setting the environment path. Not sure why though. – Badrul Apr 03 '23 at 07:27
2

You can download 64-bit Git for Windows Setup https://git-scm.com/download/win

1

Uninstall and reinstall GIT solved my problem.

1

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.

stillKonfuzed
  • 402
  • 3
  • 10
1

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

Kamlesh Singh
  • 151
  • 1
  • 5
  • 1
    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 https://github.com/flutter/flutter/issues/123995 – Terry Deng May 02 '23 at 16:12
1

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

1

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

0

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

Mob
  • 53
  • 2
  • 7
0

Try installing git from here according to your linux distro https://git-scm.com/download/linux

0

if it still not worked even after applying the above environment variables then Just run Android Studio as Administrator

Aadii Mughal
  • 169
  • 2
  • 9
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.

Dave Horner
  • 405
  • 5
  • 10
-1
C:\src\flutter\bin;C:\Windows\System32

just add this path

Vijay Vgahela
  • 139
  • 1
  • 3