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.

Community
  • 1
  • 1
Seabody
  • 1,180
  • 1
  • 12
  • 25
  • 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. – William Seiti Mizuta Feb 19 '13 at 05:27
  • 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? – Seabody Feb 19 '13 at 06:16
  • Yeah path is PATH. It is really strange. Try to run the command `git --version`. – William Seiti Mizuta Feb 19 '13 at 06:25
  • Again, it didn't work. I got the same error. – Seabody Feb 19 '13 at 06:41
  • Try to reinstall the git or use another git program. I used msysgit for windows and I liked it. – William Seiti Mizuta Feb 19 '13 at 06:45
  • @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) – Nevik Rehnel Feb 19 '13 at 08:57
  • @NevikRehnel: I didn't know that. So, if Seabody reinstall, it should work. – William Seiti Mizuta Feb 19 '13 at 16:04
  • Thank you William and Nevik, I uninstalled and reinstalled and all was good. Thanks! – Seabody Feb 23 '13 at 03:20
  • Seabody I don't think you had to reinstall. There is an answer below from @Kirk that I think should be the accepted answer. :) – Metagrapher Nov 15 '13 at 01:25
  • 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? – Seabody Nov 18 '13 at 08:47
  • 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! – Abhinav Bahiya Aug 23 '16 at 19:30

9 Answers9

159

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.

Kirk
  • 15,831
  • 19
  • 73
  • 105
  • Thank you,nice and easy solution! – laike9m Nov 06 '13 at 15:02
  • 1
    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. – Carl Dec 06 '13 at 02:23
  • Could you please explain how could I have updated GIT? I didn't actually use it - does it update itself? Creepy... – Tomáš Zato - Reinstate Monica Mar 17 '14 at 20:34
  • Awesome. Just opened the GitHub and got the message of GitHub is extracting git.. Later open the git shell, problem solved. – manu Sep 22 '14 at 08:47
  • 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 installs – mirhagk May 18 '16 at 13:36
  • This was very useful! – Parth Thakkar Jun 26 '16 at 16:49
  • 1
    Just need to confirm this was still a viable fix for 17th of August, 2016. Issue was with powershell version of posh git. – Polyducks Aug 17 '16 at 10:59
  • 06 December 2018. This fix still is needed and work. – distante Dec 06 '18 at 20:17
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/

Colin Pear
  • 2,910
  • 1
  • 26
  • 33
7

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.

Matt Bierner
  • 37,231
  • 8
  • 113
  • 148
Aaron Gibson
  • 1,106
  • 1
  • 18
  • 34
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

mca
  • 124
  • 1
  • 3
  • 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. – Luciano May 16 '17 at 12:35
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.

miken32
  • 35,483
  • 13
  • 81
  • 108
Andy Burton
  • 556
  • 6
  • 12
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.

NomanJaved
  • 1,038
  • 11
  • 27
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.

deadfish
  • 11,064
  • 11
  • 79
  • 125
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)

Community
  • 1
  • 1
Gokul NC
  • 723
  • 2
  • 11
  • 31
-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.

nicedawg
  • 144
  • 1
  • 3
  • 1
    This actually does work. For me, I changed from PowerShell to Git Bash and then changed it back to PowerShell. – slacker Apr 06 '15 at 00:04