Command-line Git on Windows

I have installed msysGit 1.7.10 on my Windows 7 machine. What I need to know is if I can still use Git from command line?

When I try the git command in the command line right now I see:

'git' is not recognized as an internal or external command, operable program or batch file.

Is there any way I can enable the Git command line?

224699 次浏览

正如@birryree 所说,将 msysgit 的二进制文件添加到您的 PATH 中,或者使用 Git Bash (据我所知,它是安装在 msysgit 中的) ,它比 Windows 的控制台更好,与 Unix 的控制台类似。

I had the same issue and resolved it by adding the /bin directory location to the PATH Environment Variable.

  1. Search for the file location where Git was installed, mine is C:\Users\(My UserName)\AppData\Local\GitHub. It may also be C:\Program Files (x86)\Git

  2. Once you have the location of Git you should see a /bin sub-folder. It may be in a PortableGit folder (mine is 复制此路径

  3. 进入控制面板 > 系统 > 系统保护 > 高级 > 环境变量

  4. 选择 PATH,单击编辑并粘贴这里的 bin 路径。如果您的 PATH 中已经有任何值,则将 Git 路径粘贴到用分号分隔的末尾。

现在您可以从 CMD 访问 Git 命令。

这些说明适用于安装了 msysgit/TortoiseGit 的 Windows 8,但应该适用于 Windows 上其他类型的 git 安装。

  • Go to 控制面板系统和安全系统
  • 单击左侧的 高级系统设置打开系统属性。
  • 点击 高级标签
  • 点击 环境 对话框底部的变量 按钮
  • 编辑 系统 变量 称为 路径.
  • Append these two paths to the list of existing paths already present in the system variable. The tricky part was two paths were required. These paths may vary for your PC. ;C:\msysgit\bin\;C:\msysgit\mingw\bin\
  • 如果 CMD 提示窗口已经打开,则关闭它。 CMD 需要重新启动才能获得更新后的 Path 变量。
  • 尝试在命令行中键入 饭桶,您将看到一个 git 命令列表向下滚动屏幕。

在 windows 8.1 中,将 PATH 环境变量设置为 Git 的 bin目录对我来说不起作用。相反,我必须使用 cmd目录 C:\Program Files (x86)\Git\cmd

感谢@VonC 在这个问题中

您可以安装 巧克力味的。它类似于 Linux 中的 apt-get,您可以使用命令行进行安装。作为管理员运行命令提示符并键入 choco install git,您将能够安装专门用于命令行的 git。

对我来说,我使用的是 Windows10,@andrew-marshall 的指令起作用了(谢谢!)除了 git.exePortableGit...而不是 bincmd目录之外,所以我必须将 \cmd放在我添加到 PATH的路径的末尾。我觉得我应该把这个贴在这里以防其他人碰到同样的问题。一旦 git在一个新的命令提示符窗口中返回命令使用信息,而不是一个错误,您就可以判断它是否正常工作。

在最新版本(我写作的时候是2.19版本的 Windows)中,如果你选择了“在命令提示符中使用 git”(或者类似的选项,安装 git 时请仔细阅读这些选项) ,你应该可以在命令提示符或者 Windows PowerShell 中使用 git 命令而不需要任何额外的设置。只要记住在安装 git 之后重新启动命令行工具。

如果已经在 Windows10中安装了 GitHubDesktop,请按 Ctrl +’。 或者在菜单中转到 Repository > Open in command 命令提示符。

如果您的计算机中没有安装 git,那么应该会出现安装 git 的提示。(我从中了解到 GitHubDesktop 和 git 是不同的应用程序)。安装 git,关闭命令提示符并再次打开它。

You can test your installation by typing in git at the command prompt.

到目前为止,使用 win 1909和 Git-2.24.0.2-64位安装程序,这个过程对用户配置非常友好。看来以前的问题现在可以解决了。