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

GitGithub for-Windows

Git Problem Overview


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.

Git Solutions


Solution 1 - Git

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 - Git

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 - Git

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 - Git

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 - Git

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.

Solution 6 - Git

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.

Solution 7 - Git

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.

Solution 8 - Git

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)

Solution 9 - Git

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSeabodyView Question on Stackoverflow
Solution 1 - GitKirkView Answer on Stackoverflow
Solution 2 - GitColin PearView Answer on Stackoverflow
Solution 3 - GitAaron GibsonView Answer on Stackoverflow
Solution 4 - GitmcaView Answer on Stackoverflow
Solution 5 - GitAndy BurtonView Answer on Stackoverflow
Solution 6 - GitNomanJavedView Answer on Stackoverflow
Solution 7 - GitdeadfishView Answer on Stackoverflow
Solution 8 - GitGokul NCView Answer on Stackoverflow
Solution 9 - GitnicedawgView Answer on Stackoverflow