找不到 git 命令,也找不到 ssh-agent
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14950355/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git command could not be found and could not find ssh-agent
提问by Seabody
I was on GitHub today and realized I was behind on updates from a repo. I tried to fetchupdates, but it failed from the outset. I received two messages when I started up Git Shell (from GitHub for Windows):
我今天在 GitHub 上,意识到我落后于 repo 的更新。我试图获取更新,但从一开始就失败了。我在启动 Git Shell 时收到两条消息(来自 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.
警告:找不到 git 命令。请创建别名或将其添加到您的 PATH。
警告:找不到 ssh-agent。
When I attempted to enter "$ git fetch origin", I got the following error message:
当我尝试输入“$ git fetch origin”时,收到以下错误消息:
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.
术语“$”不被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。
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.
我不知道发生了什么,上次我使用 Shell(本月初)时,它没有这样做。我尝试将 git.exe 的路径添加到 PATH 环境变量中,但这不起作用 - 似乎没有任何改变。这样做后我没有重新启动计算机,这是问题吗?我也从未将 Git 设置为使用 SSH。
回答by Kirk
It sounds like you recently updated GitHubapplication and Git Shellis now broken.
听起来您最近更新了GitHub应用程序,而Git Shell现在已损坏。
Short version
精简版
To fix it
要解决这个问题
- close Git Shell
- open GitHuband let it do some post installation.
- Open Git Shellagain and you should be fixed.
- 关闭Git Shell
- 打开GitHub,让它做一些安装后的工作。
- 再次打开Git Shell,你应该得到修复。
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 Shellopens
- 打开Git Shell
- 系统会提示您更新GitHub
- 更新后,Git Shell打开
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.
找不到 git 命令。请创建别名或将其添加到您的 PATH。
警告:找不到 ssh-agent。
If this is the case, do this
如果是这种情况,请执行此操作
- Close Git Shell
- Now open the GitHubapplication (not Git Shell).
- 关闭Git Shell
- 现在打开GitHub应用程序(不是Git Shell)。
This will say something along the lines of (not sure of the exact version)
这会说一些类似的东西(不确定确切的版本)
GitHub is extracting git..
GitHub 正在提取 git..
Let that go through the process and after it is complete, go open Git Shelland it is fixed. Just worked for me at least.
让它完成整个过程,完成后,打开Git Shell并修复它。至少对我有用。
回答by Colin Pear
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.
如果您不想重新安装 GitHub 或 GitShell,或者您甚至不使用该服务,那么您可以自己修复它。
Basically you just need to add the directory pathway of git.exe to your PATH environment variable in Windows.
基本上你只需要在 Windows 中将 git.exe 的目录路径添加到你的 PATH 环境变量中。
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.
对我来说,我必须添加路径“C:\Program Files (x86)\Git\bin”。或者当然你可能已经在不同的目录中安装了 Git,所以你需要找出你把它放在哪里。
Directions for doing all of this can be found here: http://thepracticalsysadmin.com/setting-up-git-in-windows/
可以在此处找到执行所有这些操作的说明:http: //thepracticalsysadmin.com/setting-up-git-in-windows/
回答by Aaron Gibson
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:
在系统变量中(下半框,滚动到该Path
部分并进行编辑。假设您的 git install 是默认位置,请将以下内容添加到当前路径的末尾:
;C:\Program Files (x86)\Git\cmd;
;C:\Program Files (x86)\Git\cmd;
Done.
完毕。
回答by mca
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
我通过打开 Github destop 应用程序解决了我的问题,单击设置 -> 选项我的默认 shell 选择是 PowerShell(它突然停止工作)我选择 Git Bash 保存它,然后打开设置->选项并再次选择 PowerShell。接下来我再次打开 GitShell,是的!它又开始工作了
回答by Andy Burton
TLDR;
TLDR;
Add a user %path%
variable with %localappdata%\GitHub\PORTAB~1\bin
添加一个用户%path%
变量%localappdata%\GitHub\PORTAB~1\bin
Long version:
长版:
I couldn't get Kirk's answer to work with Github fixing itself.
我无法得到 Kirk 与 Github 一起修复自身的答案。
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
您正在寻找的文件是 git.exe 并且 Windows GitHub GUI 将自身安装到您的本地用户应用程序目录中,这使得它很难找到,例如我的是 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.
该目录需要位于您的 Windows 环境路径中,以便git.exe
只需git
在命令窗口中键入即可找到。
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
.
我发现的最佳解决方案是打开系统环境变量(系统 -> 高级 -> 环境变量)然后添加一个新的用户变量(顶部框,而不是底部,这是系统变量)调用Path
并设置其值到%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.
这意味着系统%path%
变量具有 github bin 目录的完整用户配置文件路径,就像示例中一样。
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.
尝试直接附加%appdata%
和%userprofile%
引用系统%path%
不起作用,因为在设置系统变量时这些变量不可用,因此上述解决方案设置了一个用户%path%
变量,它允许调用%localappdata%
etc,并自动附加到系统%path%
,达到预期的效果。
回答by NomanJaved
Follow the simple steps:
请按照以下简单步骤操作:
- Open the
gitshell
update it and then close it. - Open the
github
not thegitshell
it will extract the files auto (mean update it also). - Again open the
gitshell
.
- 打开
gitshell
更新它然后关闭它。 - 打开
github
不gitshell
将文件解压汽车(平均更新也)。 - 再次打开
gitshell
.
you will see the error will finish. Hope this will help you too.
你会看到错误会结束。希望这也能帮助你。
回答by deadfish
I had this problem on Windows7 with installed latest github program. I even disabled all functionalities my antivirus :)
我在安装了最新 github 程序的 Windows7 上遇到了这个问题。我什至禁用了我的防病毒软件的所有功能:)
My solution was to open as administratorprogram powershell ise
(from menu) and run this command:
我的解决方案是以管理员程序powershell ise
(从菜单)打开并运行以下命令:
Set-ExecutionPolicy Unrestricted
You will get dialog with question, I clicked yes. Then I closed all windows and reruned github shell without any problems.
你会得到有问题的对话,我点击是。然后我关闭了所有窗口并重新运行了 github shell,没有任何问题。
回答by Gokul NC
My easy solution(for GitHub desktopusers):
我的简单解决方案(适用于GitHub 桌面用户):
- Create a batch file
git.bat
:
- 创建批处理文件
git.bat
:
@echo off
%LocalAppData%\GitHub\Portab~1\cmd\git.exe %*
@回声关闭
%LocalAppData%\GitHub\Portab~1\cmd\git.exe %*
- Move it to
C:\Windows\
folder..
- 移动到
C:\Windows\
文件夹..
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)
注意:您也可以使用git.bat
而不是git.exe
直接使用..对于需要您显式指向 git 可执行文件的软件(如Android Studio)很有用
回答by nicedawg
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.
转到“工具”->“选项”,然后将默认 shell 从“PowerShell”更改为“Git Bash”或其他内容。