git command could not be found and could not find ssh-agent
Asked Answered
U

9

82

I was on GitHub today and realized I was behind on updates from a repo. I tried to fetch updates, but it failed from the outset. I received two messages when I started up Git Shell (from GitHub for Windows):

Warning: git command could not be found. Please create an alias or add it to your PATH.

Warning: Could not find ssh-agent.

When I attempted to enter "$ git fetch origin", I got the following error message:

The term '$' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

I also tried omitting the $ sign, but that didn't change anything.

I have no clue what's going on, the last time I used the Shell (beginning of this month), it did not do this. I have tried adding the path to git.exe to the PATH environment variable, but that did not work - nothing appeared to change. I have not restarted my computer after doing so, is that the problem? I have also never set up Git to use SSH.

Undecided answered 19/2, 2013 at 5:19 Comment(11)
It seems that you don't have git installed or it is not in your path. Have you opened the correct shell? Look in your path and verify if the git.exe directory is present in the list.Astragal
By "path", do you mean the PATH environment variable? I added the path to git.exe onto it, no change. I installed Github for Windows, I was under the impression it installed everything I needed?Undecided
Yeah path is PATH. It is really strange. Try to run the command git --version.Astragal
Again, it didn't work. I got the same error.Undecided
Try to reinstall the git or use another git program. I used msysgit for windows and I liked it.Astragal
@WilliamSeitiMizuta: Github for Windows comes with a portable minimal version of msysgit, so that should work out of the box. Seabody: Reinstallation should fix your problem. Just uninstall Github for Windows from your computer, and install again (download the latest version from github just to be sure)Dougherty
@NevikRehnel: I didn't know that. So, if Seabody reinstall, it should work.Astragal
Thank you William and Nevik, I uninstalled and reinstalled and all was good. Thanks!Undecided
Seabody I don't think you had to reinstall. There is an answer below from @Azriel that I think should be the accepted answer. :)Vapory
I'm not sure on SO policy (I don't use the site an awful lot) -- am I allowed to accept his answer, bearing in mind it was neither posted nor the way I solved the problem? Or is community consensus that it is the right answer enough to allow me to accept it? I'm aware that I can physically accept it but am I actually allowed to?Undecided
You don't need to do many things. Just close the Git Desktop and Shell both and then restart again. It will work fine. Don't worry. If still it not working properly then do it for one time. then definitely it will work. Thanks!Dyscrasia
A
158

It sounds like you recently updated GitHub application and Git Shell is now broken.

Short version

To fix it

  • close Git Shell
  • open GitHub and let it do some post installation.
  • Open Git Shell again and you should be fixed.

Long version

This just happened to me and just to make sure I follow you, you just did this

  • Open Git Shell
  • You are prompted to update GitHub
  • After the update, Git Shell opens

Now it gives the error

git command could not be found. Please create an alias or add it to your PATH.

Warning: Could not find ssh-agent.

If this is the case, do this

  • Close Git Shell
  • Now open the GitHub application (not Git Shell).

This will say something along the lines of (not sure of the exact version)

GitHub is extracting git..

Let that go through the process and after it is complete, go open Git Shell and it is fixed. Just worked for me at least.

Azriel answered 25/7, 2013 at 3:46 Comment(7)
Just happened to me 12/5/2013, exactly as described in the OP, so apparently this glitch is still not fixed. Some of us mainly use the shell and thus might take a while to discover this. Your procedure fixed the problem.Credits
Could you please explain how could I have updated GIT? I didn't actually use it - does it update itself? Creepy...Ceuta
Awesome. Just opened the GitHub and got the message of GitHub is extracting git.. Later open the git shell, problem solved.Flaring
Got this in 2016, so still very much an issue. Thanks for the proper fix though, previously I've done some horrible workarounds to get this to work. If only github could simply open the application after the tool installsDishonest
This was very useful!Binding
Just need to confirm this was still a viable fix for 17th of August, 2016. Issue was with powershell version of posh git.Mountainside
06 December 2018. This fix still is needed and work.Recife
N
10

If you don't want to goof around with reinstalling GitHub or GitShell or if your are not even using that service then you can fix it yourself.

Basically you just need to add the directory pathway of git.exe to your PATH environment variable in Windows.

For me I had to add the path "C:\Program Files (x86)\Git\bin." Or course you may have installed Git in a different directory so you will need to find out where you put it.

Directions for doing all of this can be found here: http://thepracticalsysadmin.com/setting-up-git-in-windows/

Neo answered 6/3, 2014 at 17:52 Comment(0)
U
8

System > Advanced System Settings > Advanced Tab > Environment Variables (At the bottom).

In System Variables (The bottom half box, scroll to the Path section and edit. Assuming your git install was default location, add the below to the end of the current path:

;C:\Program Files (x86)\Git\cmd;

Done.

Unpolite answered 6/3, 2015 at 14:53 Comment(0)
W
6

I solved my problem by opening Github destop app, click settings ->options My default shell selection was PowerShell (it stopped working all of a sudden) I selected Git Bash saved it, then open settings- >options and chose PowerShell again. Next I opened GitShell again and yes! it started working again

Winer answered 26/9, 2016 at 13:8 Comment(1)
This worked but only after I did 'settings' --> 'open in git shell' first. And only then did I get this to work from the start menu 'git shell' shortcut.Naumachia
M
5

TLDR;

Add a user %path% variable with %localappdata%\GitHub\PORTAB~1\bin

Long version:

I couldn't get Kirk's answer to work with Github fixing itself.

The file you are looking for is git.exe and the Windows GitHub GUI installs itself to your local user app directory which makes it rather difficult to find e.g. mine was C:\Users\andy_000\AppData\Local\GitHub\PortableGit_ed44d00daa128db527396557813e7b68709ed0e2\bin\git.exe

This directory needs to be in your windows environment path in order for git.exe to be found just by typing git in a command window.

The best solution I've found is to open your system environmental variables (System -> Advanced -> Environmental Variables) then just add a new user variable (the top box, not the bottom, which is system variables) called Path and set its value to %localappdata%\GitHub\PORTAB~1\bin.

This will mean that the system %path% variable has the full user profile path to the github bin directory just as in the example.

Attempts to append %appdata% and %userprofile% references directly to the system %path% do not work as these variables are not available when the system variables are set, so the solution above sets a user %path% variable, which does allow calls to %localappdata% etc, and which is automatically appended to the system %path%, giving the desired effect.

Misestimate answered 28/10, 2014 at 11:52 Comment(0)
P
4

Follow the simple steps:

  1. Open the gitshell update it and then close it.
  2. Open the github not the gitshell it will extract the files auto (mean update it also).
  3. Again open the gitshell.

you will see the error will finish. Hope this will help you too.

Pentacle answered 3/12, 2014 at 16:6 Comment(0)
S
2

I had this problem on Windows7 with installed latest github program. I even disabled all functionalities my antivirus :)

My solution was to open as administrator program powershell ise (from menu) and run this command:

Set-ExecutionPolicy Unrestricted

You will get dialog with question, I clicked yes. Then I closed all windows and reruned github shell without any problems.

Skilled answered 12/7, 2013 at 20:0 Comment(0)
H
0

My easy solution (for GitHub desktop users):

  1. Create a batch file git.bat:

@echo off

%LocalAppData%\GitHub\Portab~1\cmd\git.exe %*

  1. Move it to C:\Windows\ folder..

That's it!! You're done!!

Note: You can also use git.bat instead of using git.exe directly.. It'll be useful for softwares that require you to point the git executable explicitly (like Android Studio)

Haemostat answered 17/3, 2017 at 15:23 Comment(0)
F
-1

Another option is to change your default shell.

Go to Tools -> Options, and change your default shell from "PowerShell" to "Git Bash" or something else.

Fleurdelis answered 28/5, 2013 at 15:41 Comment(1)
This actually does work. For me, I changed from PowerShell to Git Bash and then changed it back to PowerShell.Typography

© 2022 - 2024 — McMap. All rights reserved.