使用适用于 Windows 的 GitHub 客户端在 PATH 中安装 Git
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26620312/
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
Installing Git in PATH with GitHub client for Windows
提问by brentonstrine
How do I install Git in my PATH
when using the GitHub client for Windows?
PATH
使用适用于 Windows 的 GitHub 客户端时,如何在我的计算机中安装 Git ?
I'm running into errors because apparently Git is not installed in PATH. For example, using Atom, trying to install the Linter plugin gives this error:
我遇到了错误,因为显然 Git 没有安装在 PATH 中。例如,使用 Atom,尝试安装 Linter 插件会出现以下错误:
npm ERR! not found: git
npm ERR!
npm ERR! Failed using git.
npm ERR! This is most likely not a problem with npm itself.
npm ERR! Please check if you have git installed and in your PATH.
Does GitHub for Windows install Git when it installs? (It must, otherwise how does it use Git?) I don't want to double-install it... so how do I just add the Git that's already there to PATH?
GitHub for Windows 安装时会安装 Git 吗?(它必须,否则它如何使用 Git?)我不想双重安装它......那么我如何将已经存在的 Git 添加到 PATH?
回答by brentonstrine
GitHub for Windows does indeed install its own version of Git, but it doesn't add it to the PATH
variable, which is easy enough to do. Here's instructions on how to do it:
GitHub for Windows 确实安装了自己的 Git 版本,但它没有将它添加到PATH
变量中,这很容易做到。以下是有关如何操作的说明:
Get the Git URL
We need to get the url of the Git
\cmd
directory your computer. Git is located here:C:\Users\<user>\AppData\Local\GitHub\PortableGit_<guid>\cmd\git.exe
So on your computer, replace
<user>
with your user and find out what the<guid>
is for your computer. (Theguid
may change each time GitHub updates PortableGit, but they're working on a solution to that.)Copy it and paste it into a command prompt (right-click > paste to paste in the terminal) to verify that it works. You should see the Git help response that lists common Git commands. If you see
The system cannot find the path specified.
Then the URL isn't right. Once you have it right, create the link to the directory using this format:;C:\Users\<user>\AppData\Local\GitHub\PortableGit_<guid>\cmd
(Note:
\cmd
at the end, not\cmd\git.exe
anymore!)On my system, it's this, yours will be different:
;C:\Users\brenton\AppData\Local\GitHub\PortableGit_7eaa494e16ae7b397b2422033as45d8ff6ac2010\cmd
Edit the PATH Variable
Navigate to the Environmental Variables Editor (instructions) and find the
Path
variable in the “System Variables” section. ClickEdit…
and paste the URL of Git to the end of that string. Save! It might be easier to pull this into Notepad to do the edit, just make sure you put onesemicolon before you paste in the URL. If it doesn't work it's probably because this path got messed up either with a space in there somewhere (should be no spaces around the semicolon) or a semicolon at the end (semicolons should only separate URLs, no semicolon at beginning or end of string).
获取 Git 网址
我们需要获取
\cmd
您计算机的 Git目录的 url 。Git位于:C:\Users\<user>\AppData\Local\GitHub\PortableGit_<guid>\cmd\git.exe
因此,在您的计算机上,替换
<user>
为您的用户并找出<guid>
适合您计算机的内容。(guid
每次 GitHub 更新 PortableGit 时可能会发生变化,但他们正在研究解决方案。)将其复制并粘贴到命令提示符中(右键单击 > 粘贴以粘贴到终端中)以验证它是否有效。您应该会看到列出常见 Git 命令的 Git 帮助响应。如果您看到
The system cannot find the path specified.
那么 URL 是错误的。确定后,使用以下格式创建指向目录的链接:;C:\Users\<user>\AppData\Local\GitHub\PortableGit_<guid>\cmd
(注意:
\cmd
最后,\cmd\git.exe
不再!)在我的系统上,就是这样,你的会有所不同:
;C:\Users\brenton\AppData\Local\GitHub\PortableGit_7eaa494e16ae7b397b2422033as45d8ff6ac2010\cmd
编辑 PATH 变量
导航到环境变量编辑器(说明)并
Path
在“系统变量”部分找到变量。单击Edit…
并将 Git 的 URL 粘贴到该字符串的末尾。节省!将其拉入记事本进行编辑可能更容易,只需确保在粘贴 URL 之前输入一个分号。如果它不起作用,可能是因为这条路径在某处有一个空格(分号周围应该没有空格)或最后有一个分号(分号应该只分隔 URL,在开头或结尾没有分号)细绳)。
If it worked, you should be able to close & reopen a terminal and type git
and it will give you that same git help file. Then installing the Linter should work. (Atom > File > Settings > Packages > Linter)
如果它有效,您应该能够关闭并重新打开终端并输入git
,它会给您相同的 git 帮助文件。然后安装 Linter 应该可以工作。(Atom > 文件 > 设置 > 包 > Linter)
回答by Adnan Ali
I would like to add one more thing to what the other answers have said. It is not compulsory that path will be:
我想在其他答案所说的内容中再添加一件事。路径不是强制性的:
C:\Users\<user>\AppData\Local\GitHub\PortableGit_<guid>\bin\git.exe
C:\Users\<user>\AppData\Local\GitHub\PortableGit_<guid>\bin\git.exe
In my computer I did not found Git
there.
在我的电脑里我没有找到Git
。
BUT git and cmd are located in
但是 git 和 cmd 位于
git.exe
git.exe
C:\Program Files\Git\bin\git.exe
cmd
指令
C:\Program Files\Git\cmd
To add into PATH:
要添加到 PATH:
- Right-Click on My Computer
- Click on Advanced System Settings
- Click on Environment Variables
- Then, under System Variables, look for the path variable and click edit
Add the path to git's bin and cmd at the end of the string like this:
;C:\Program Files\Git\bin\git.exe;C:\Program Files\Git\cmd
- 右键单击我的电脑
- 点击高级系统设置
- 点击环境变量
- 然后,在系统变量下,查找路径变量并单击编辑
在字符串的末尾添加 git 的 bin 和 cmd 路径,如下所示:
;C:\Program Files\Git\bin\git.exe;C:\Program Files\Git\cmd
OR
或者
;C:\Users\<user>\AppData\Local\GitHub\PortableGit_<guid>\bin;C:\Users\<user>\AppData\Local\GitHub\PortableGit_<guid>\cmd
;C:\Users\<user>\AppData\Local\GitHub\PortableGit_<guid>\bin;C:\Users\<user>\AppData\Local\GitHub\PortableGit_<guid>\cmd
To verify, restart cmd and type git --version
in cmd
要验证,请重新启动 cmd 并输入git --version
cmd
回答by Gaurav khurana
Thanks everyone who have answered.I have seen all answers and to try to make it easy for everyone
感谢所有回答的人。我已经看到了所有的答案,并试图让每个人都轻松
Step 1: Type edit environmentand select the option shown
第 1 步:输入编辑环境并选择显示的选项
Step 2: Select Path and click on edit
第 2 步: 选择路径并点击编辑
Step 3:In the end add the below statement(you can avoid the first ; if its already there)
第 3 步:最后添加以下语句(您可以避免第一个;如果它已经存在)
;C:\Program Files\Git\bin\git.exe;C:\Program Files\Git\cmd
Step 4:- Click on ok
第 4 步:- 单击确定
Step 5 **:- One of the important step which is highlighted by one of the users. thanks to him. Please, **CLOSEcommand prompt and REOPENthen try to write git.
步骤 5 **:- 其中一位用户强调的重要步骤之一。感谢他。请**关闭命令提示符并重新打开,然后尝试编写 git。
**
**
- Close command prompt and restart before trying the below command
- 在尝试以下命令之前关闭命令提示符并重新启动
**
**
Here is the magic
这就是魔法
回答by Samuel Auger
I installed GitHubDesktop on Windows 10 and git.exe is located there: C:\Users\john\AppData\Local\GitHubDesktop\app-0.7.2\resources\app\git\cmd\git.exe
我在 Windows 10 上安装了 GitHubDesktop,git.exe 位于那里:C:\Users\john\AppData\Local\GitHubDesktop\app-0.7.2\resources\app\git\cmd\git.exe
回答by Prabin Tp
Git's executable is actually located in:
C:\Users\<user>\AppData\Local\GitHub\PortableGit_<guid>\bin\git.exe
Git 的可执行文件实际上位于:
C:\Users\<user>\AppData\Local\GitHub\PortableGit_<guid>\bin\git.exe
Now that we have located the executable all we have to do is add it to our PATH:
现在我们已经找到了可执行文件,我们要做的就是将它添加到我们的 PATH 中:
- Right-Click on My Computer
- Click Advanced System Settings
- Click Environment Variables
- Then under System Variables look for the path variable and click edit
- Add the path to git's bin and cmd at the end of the string like this:
- 右键单击我的电脑
- 单击高级系统设置
- 单击环境变量
- 然后在系统变量下查找路径变量并单击编辑
- 在字符串的末尾添加 git 的 bin 和 cmd 路径,如下所示:
;C:\Users\<user>\AppData\Local\GitHub\PortableGit_<guid>\bin;C:\Users\<user>\AppData\Local\GitHub\PortableGit_<guid>\cmd
;C:\Users\<user>\AppData\Local\GitHub\PortableGit_<guid>\bin;C:\Users\<user>\AppData\Local\GitHub\PortableGit_<guid>\cmd
回答by Darlesson
GitHub for Windows is now GitHub desktop.
GitHub for Windows 现在是GitHub desktop。
If you have GitHub for Windows(before version 1.1), your path should be:
如果你有Windows版GitHub(1.1 版之前),你的路径应该是:
C:\Users\<user>\AppData\Local\GitHub\PortableGit_<guid>\cmd
C:\Users\<user>\AppData\Local\GitHub\PortableGit_<guid>\cmd
If you have GitHub Desktop(from version 1.1), your path should be:
如果你有GitHub Desktop(从 1.1 版开始),你的路径应该是:
C:\Users\<user>\AppData\Local\GitHubDesktop\app-<version>\resources\app\git\cmd
C:\Users\<user>\AppData\Local\GitHubDesktop\app-<version>\resources\app\git\cmd
After confirming and copying your path, do the following:
确认并复制您的路径后,请执行以下操作:
- Right click on My Computer or This PC
- Click on Properties
- Click on Advanced system settings
- Click on Environment Variables under the Advanced tab
- Add your path with
;
before it in the variable Path - Press Ok
- Use a new terminal
- 右键单击我的电脑或这台电脑
- 点击属性
- 点击高级系统设置
- 单击高级选项卡下的环境变量
;
在变量 Path 中添加您的路径- 按确定
- 使用新终端
回答by Marwa Eltayeb
Add
添加
C:\Program Files\Git\bin\git.exe;C:\Program Files\Git\cmd;C:\Windows\System32
to your PATH variable
到您的 PATH 变量
Do not create new variable for git but add them as I did one after another separating them by ;
不要为 git 创建新变量,而是像我一样添加它们,用 ;
It works for me
这个对我有用
回答by K7Buoy
Having searched around several posts. On Windows 10 having downloaded and installed Github for Windows 2.10.2 I found the git.exe in
搜索了几个帖子。在 Windows 10 上下载并安装了适用于 Windows 2.10.2 的 Github,我在
C:\Users\<user>\AppData\Local\Programs\Git\bin
and the git-cmd.exe in
和 git-cmd.exe 中的
C:\Users\<user>\AppData\Local\Programs\Git
Please note the change to Programs folder within Local from the above posts.
请注意上述帖子中本地中程序文件夹的更改。
回答by Robert MontgomeryBurns
To get this to work I had to combine many of the above answers, to anyone who this might help here is my much simpler process.
为了让它起作用,我必须结合上面的许多答案,对于这可能对这里有帮助的任何人来说,这是我的简单得多的过程。
If you have Windows 10 just start typing "edit environmental..." and it'll pop up right away. Click path and Edit… then paste the ;C:\Program Files\Git\bin\git.exe;C:\Program Files\Git\cmd
at the end of the path already there, don't forget the ; to separate your new github path from the current path.
如果您使用的是 Windows 10,只需开始输入“编辑环境...”,它就会立即弹出。单击路径和编辑...然后将 粘贴到;C:\Program Files\Git\bin\git.exe;C:\Program Files\Git\cmd
已经存在的路径末尾,不要忘记 ; 将您的新 github 路径与当前路径分开。
You do not need the guid but if you want to know how to find it open bash, type git --man-path
您不需要 guid,但如果您想知道如何找到它,请打开 bash,键入 git --man-path
回答by Rubin Luitel
Updated for the Github Desktop
针对 Github 桌面更新
Search up "Edit the system environment variables" on windows search
在 Windows 搜索中搜索“编辑系统环境变量”
Click environmental variableon the bottom right corner
Find pathunder system variables and click edit on it
Click newto add a new path
add this path: C:\Users\yourUserName\AppData\Local\GitHubDesktop\bin\github.exe
点击右下角的环境变量
在系统变量下找到路径并点击编辑
单击新建以添加新路径
添加此路径:C:\Users\yourUserName\AppData\Local\GitHubDesktop\bin\github.exe
To make sure everything is working fine, open cmd, and type github.exe
为了确保一切正常,打开 cmd,然后输入 github.exe