git command could not be found and could not find ssh-agent

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.


Solution 1:

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.

Solution 2:

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/

Solution 3:

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.

Solution 4:

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

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