Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Powershell下载和安装git client for Windows_Git_Powershell - Fatal编程技术网

如何使用Powershell下载和安装git client for Windows

如何使用Powershell下载和安装git client for Windows,git,powershell,Git,Powershell,我必须为从gihtub克隆存储库编写自动化powershell脚本,但我需要使用命令行安装git。请告诉我如何使用命令行在Windows上下载并安装git,而无需进行任何手动操作 提前谢谢 您可以使用脚本编写Git的安装 文件包记录在 首先你必须 那么命令是: choco安装-y git 我希望不用巧克力也能做到这一点。以下内容适用于我,使用powershell下载并安装64位版本的git for windows: # get latest download url for git-for-wi

我必须为从gihtub克隆存储库编写自动化powershell脚本,但我需要使用命令行安装git。请告诉我如何使用命令行在Windows上下载并安装git,而无需进行任何手动操作


提前谢谢

您可以使用脚本编写Git的安装

文件包记录在

  • 首先你必须
  • 那么命令是:
  • choco安装-y git


    我希望不用巧克力也能做到这一点。以下内容适用于我,使用powershell下载并安装64位版本的git for windows:

    # get latest download url for git-for-windows 64-bit exe
    $git_url = "https://api.github.com/repos/git-for-windows/git/releases/latest"
    $asset = Invoke-RestMethod -Method Get -Uri $git_url | % assets | where name -like "*64-bit.exe"
    # download installer
    $installer = "$env:temp\$($asset.name)"
    Invoke-WebRequest -Uri $asset.browser_download_url -OutFile $installer
    # run installer
    $git_install_inf = "<install inf file>"
    $install_args = "/SP- /VERYSILENT /SUPPRESSMSGBOXES /NOCANCEL /NORESTART /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS /LOADINF=""$git_install_inf"""
    Start-Process -FilePath $installer -ArgumentList $install_args -Wait
    
    通过对类似问题的回答了解了安装参数文件:

    运行此命令需要重新启动shell,以便更新Path环境变量并使git命令正常工作。或者,您可以使用更新当前powershell路径环境变量

    $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
    

    这将在path变量中包含git.exe的路径。

    您不会。。在windows中,您可以通过从exe而不是从命令行安装来完成。非常感谢:)这真的很有帮助。我已经成功安装了git,但一旦我尝试检查git--version,我就是例外git:术语“git”不能识别为cmdlet、函数、脚本文件或可操作程序的名称。请检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。在第1行char:1+git--version+~~~~+CategoryInfo:ObjectNotFound:(git:String)[],CommandNotFoundException+FullyQualifiedErrorId:CommandNotFoundException“@PriyaRani这听起来好像git根本不在路上。看起来安装命令成功了吗?是的。。。Chocolate v0.10.8安装以下软件包:git通过安装接受软件包的许可证。git v2.14.2.20170927[已批准]git程序包文件安装已完成。执行其他安装步骤。git的安装成功。软件安装位置未明确设置,如果安装程序成功,则可能位于软件包或默认安装位置。安装成功,但我无法获取路径。我查过了
    $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")