64

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?

5
  • please create an answer for that and accept don't just write solved and thanks Jul 10, 2018 at 11:03
  • Thanks, someone already did it. Will do so next time. Jul 11, 2018 at 14:46
  • @NikolayShindarov accept the answer if its correct Jul 13, 2018 at 4:11
  • I deleted the .gradle file and it worked well. Actually, it reduces the indexing time also. Jul 3, 2022 at 17:42
  • 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.
    – Badrul
    Apr 2 at 21:37

22 Answers 22

52

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

8
  • 2
    This fixes my problem. Been reinstalling git 5 times not including yesterday attempts. Geez!
    – Yura
    Mar 5 at 3:21
  • 1
    Didnt work. I already installed git.
    – chitgoks
    Mar 18 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 3 at 7:20
  • Thank you! Please know your solution saved my sanity 3 years after you posted it.
    – Racso
    Apr 17 at 3:32
  • 2
    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. Jul 23 at 12:35
39

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 ;

8
  • This solution can work only for Windows, it must be said (the question is about Linux)
    – xKobalt
    Jul 24, 2020 at 8:02
  • 1
    What does teh semicolon do?
    – rfii
    Dec 18, 2020 at 22:11
  • In user variable section or system variable section? Feb 10, 2021 at 10:27
  • I have been trying for days to get it solved, tried so many things. And today after two days when I tried to fix my issue, this solution just made it running fine. Feb 13, 2021 at 11:47
  • You need a way to separate the entries. Each operating system can use whatever character, but the two most popular are semi-colon (on Windows) and colon (on most systems Unix, e.g. Mac OS X). @rfii Feb 18, 2021 at 22:29
38

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
  • 2
    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') Jul 23 at 12:23
32

Install it using following command.

sudo apt-get install git
17

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

3
  • This solution can work only for Windows, it must be said (the question is about Linux)
    – xKobalt
    Jul 24, 2020 at 8:03
  • 10
    Yes, i am aware of that. But i just shared to help windows users which are directed here like me. Jul 24, 2020 at 8:15
  • 1
    Yeah I'm trying to work out why this is - not sure I want to be in admin mode all the time.
    – Badrul
    Apr 3 at 7:28
11

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

2
  • This solution can work only for Windows, it must be said (the question is about Linux)
    – xKobalt
    Jul 24, 2020 at 8:03
  • For windows this was the answer that fixed my issue Feb 3, 2021 at 18:02
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.

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

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.
    – Community Bot
    Oct 26, 2021 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 3 at 7:27
2

Uninstall and reinstall GIT solved my problem.

1
  • 1
    i reinstalled git bash and it worked for me as well.
    – PTT
    Jan 7, 2021 at 11:28
2

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

2

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

1
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.

0
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

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

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.

0

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.

0

After trying everything and none worked, I reopen Android Studio as Administration and it worked...

I hope this works for anyone

-1
C:\src\flutter\bin;C:\Windows\System32

just add this path

2
  • 1
    It isn't an answer! What do you mean "just believe me". Detail your answer, please Oct 13, 2020 at 8:26
  • Please expand your answer, this is not a satisfactory answer!
    – Pluto
    Oct 13, 2020 at 8:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.