How to solve "Unable to find git in your PATH" on Flutter?
Asked Answered
M

31

85

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?

Macfadyn answered 10/7, 2018 at 10:56 Comment(5)
please create an answer for that and accept don't just write solved and thanksColton
Thanks, someone already did it. Will do so next time.Macfadyn
@NikolayShindarov accept the answer if its correctBankhead
I deleted the .gradle file and it worked well. Actually, it reduces the indexing time also.Symer
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.Photoperiod
B
32

Install it using following command.

sudo apt-get install git
Bankhead answered 10/7, 2018 at 11:8 Comment(1)
it doesn't work in windows! Says, sudo is not recognized as an internal or external command!Goodsized
V
90

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

Vookles answered 20/2, 2023 at 15:56 Comment(10)
This fixes my problem. Been reinstalling git 5 times not including yesterday attempts. Geez!Charlottetown
Didnt work. I already installed git.Endaendall
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.Photoperiod
Thank you! Please know your solution saved my sanity 3 years after you posted it.Click
flutter really should clarify their error message for this one. I would never have guessed this was the issue looking at the error messageAryn
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.Piatt
there is no flutter base directory in my case only tools/dart-sdkGoldstone
worked for me. Pay attention to slashes, don't do \ but /. I installed via chocolatey and did git config --global --add safe.directory C:/tools/flutterEyewitness
Thanks, this worked for me, I'm using Windows 11.Reeder
Just moved my 'flutter' folder from C to a less secure sensitive folder like Documents. unfortunately none of the listed solution worked for me...Culliton
D
58

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

Devout answered 2/5, 2023 at 16:24 Comment(1)
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')Piatt
P
42

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 ;

Prewar answered 25/3, 2019 at 19:21 Comment(8)
This solution can work only for Windows, it must be said (the question is about Linux)Carmelo
What does teh semicolon do?Stadiometer
In user variable section or system variable section?Lyricist
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.Roybal
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). @StadiometerPrewar
system variable section @SumitShuklaPrewar
Glad to hear that @Rizwan SohaibPrewar
Doesnt work anymoreEndaendall
B
32

Install it using following command.

sudo apt-get install git
Bankhead answered 10/7, 2018 at 11:8 Comment(1)
it doesn't work in windows! Says, sudo is not recognized as an internal or external command!Goodsized
C
21

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

Cheremkhovo answered 17/5, 2020 at 11:48 Comment(3)
This solution can work only for Windows, it must be said (the question is about Linux)Carmelo
Yes, i am aware of that. But i just shared to help windows users which are directed here like me.Maudemaudie
Yeah I'm trying to work out why this is - not sure I want to be in admin mode all the time.Photoperiod
H
11

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

Hirsch answered 24/7, 2020 at 7:35 Comment(2)
This solution can work only for Windows, it must be said (the question is about Linux)Carmelo
For windows this was the answer that fixed my issueGoldenseal
N
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.

Neogene answered 14/12, 2020 at 20:49 Comment(0)
B
5

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 *
Brat answered 23/3 at 6:51 Comment(0)
C
4

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)

  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

Clomb answered 26/10, 2021 at 16:7 Comment(2)
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.Unscramble
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.Photoperiod
A
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.

Adamsun answered 13/5, 2023 at 14:3 Comment(0)
G
3

Uninstall and reinstall GIT solved my problem.

Granny answered 20/10, 2020 at 4:11 Comment(1)
i reinstalled git bash and it worked for me as well.Dishevel
M
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.

Menchaca answered 21/12, 2020 at 6:4 Comment(0)
B
2

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

Boffin answered 17/3, 2023 at 6:20 Comment(3)
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/123995Devout
Thank you Terry you saved me, none of the answers didStereogram
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 workedStereogram
A
2

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!

Algetic answered 16/5 at 11:10 Comment(0)
R
1

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

Rewarding answered 14/12, 2020 at 3:52 Comment(0)
P
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

Prim answered 25/5, 2023 at 3:17 Comment(0)
B
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.

Baggy answered 10/10, 2023 at 8:1 Comment(0)
M
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
Marijane answered 15/4 at 18:8 Comment(0)
Q
0

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

Quoit answered 12/4, 2023 at 22:25 Comment(0)
C
0

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

Clinch answered 18/5, 2023 at 15:33 Comment(0)
I
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.

Incompatible answered 25/7, 2023 at 0:55 Comment(0)
C
-1
C:\src\flutter\bin;C:\Windows\System32

just add this path

Cavill answered 13/10, 2020 at 7:50 Comment(2)
It isn't an answer! What do you mean "just believe me". Detail your answer, pleaseAerograph
Please expand your answer, this is not a satisfactory answer!Rhenium
H
-1

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

Habiliment answered 12/6, 2021 at 9:0 Comment(0)
H
-1

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

Henrique answered 28/7, 2021 at 16:53 Comment(0)
H
-1

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

I hope this works for anyone

Holland answered 9/11, 2023 at 13:0 Comment(0)
S
-1

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:

enter image description here

Sabba answered 4/2 at 19:23 Comment(0)
B
-1

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 :) .

Beetle answered 2/5 at 20:16 Comment(0)
S
-1

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.

Strohbehn answered 22/5 at 15:8 Comment(0)
P
-1

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

Prolepsis answered 9/6 at 5:54 Comment(0)
G
-1

open vscode as administrator, that solved my problem.

Grisaille answered 13/7 at 2:21 Comment(0)
B
-2

It worked successfully when I started Android Studio as Administrator

Baronet answered 20/2 at 11:12 Comment(5)
3 other answers -- on this page -- already mention running as Administrator.Indocile
@JeffSchaller Have I braked any rule or something which is against community guidelines?Baronet
Yes; in the Help Center, under the section for Answering, is a page titled Why and how are some answers deleted?. In that page, it says: "Answer posts that do not fundamentally answer the question may be removed. This includes answers that are ... exact duplicates of other answers". Having duplicate answers means that voting is spread out among those duplicates, making it harder for future visitors to find the best answer.Indocile
See also meta.#256071Indocile
@JeffSchaller Thank you. I'll keep in mind next time.Baronet

© 2022 - 2024 — McMap. All rights reserved.