파워쉘을 이용한 window용 git client 다운로드 및 설치 방법
gittub에서 저장소 복제를 위한 자동 파워셸 스크립트를 작성해야 하는데 명령줄을 사용하여 git를 설치해야 합니다.수작업 없이 command line을 사용하여 window에 git을 다운로드하여 설치하는 방법을 알려주시겠습니까?
미리 감사드립니다!
초콜릿을 사용하지 않고 똑같이 하려고 했습니다.파워셸을 사용하여 64비트 버전의 git-for-window를 다운로드하고 설치하는 방법은 다음과 같습니다.
# 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
어디에<install inf file>
git 설치에 대한 설치 매개 변수가 들어 있는 파일의 경로입니다.예를 들어, 이것은 제가 사용하고 있는 것입니다(git installer exe를 통해 한 번 실행하여 얻은 것입니다)./SAVEINF=<install inf file>
매개변수):
[Setup]
Lang=default
Dir=C:\Program Files\Git
Group=Git
NoIcons=0
SetupType=default
Components=ext,ext\shellhere,ext\guihere,gitlfs,assoc,autoupdate
Tasks=
EditorOption=VIM
CustomEditorPath=
PathOption=Cmd
SSHOption=OpenSSH
TortoiseOption=false
CURLOption=WinSSL
CRLFOption=LFOnly
BashTerminalOption=ConHost
PerformanceTweaksFSCache=Enabled
UseCredentialManager=Enabled
EnableSymlinks=Disabled
EnableBuiltinInteractiveAdd=Disabled
이 답변에서 비슷한 질문인 https://superuser.com/a/1005634/1104046 에 대한 설치 매개 변수 파일에 대해 알게 되었습니다.
이 작업을 실행하려면 경로 환경 변수를 업데이트하고 git 명령이 작동하려면 셸을 다시 시작해야 합니다.또는 현재 powershell Path 환경 변수를
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
그러면 깃으로 가는 경로가 포함됩니다.경로 변수에서 exe.
Chocolatey를 사용하여 Git 설치 스크립트를 작성할 수 있습니다.
패키지는 https://chocolatey.org/packages/git 에서 문서화되어 있습니다.
- 먼저 초콜릿을 설치해야 하지만 명령 줄에서 설치할 수 있습니다.
- 그렇다면 명령은 다음과 같습니다.
초코설치 -ygit
하나의 명령 솔루션
Powershell을 열고 다음 명령을 입력합니다.winget install --id Git.Git -e --source winget
파워셸을 다시 시작하면 Git가 명령 줄에 있게 됩니다.
CI에서 도커 파일을 통해 설치하려면
FROM mcr.microsoft.com/windows/servercore:ltsc2019
# Assuming that you have "install-git-instructions.txt" file in the directory where this Dockerfile is located
ADD install-git-instructions.txt .
RUN powershell.exe -Command \
$ErrorActionPreference = 'Stop'; \
$ErrorActionPreference = 'Stop'; \
(New-Object System.Net.WebClient).DownloadFile('https://github.com/git-for-windows/git/releases/download/v2.39.0.windows.1/Git-2.39.0-64-bit.exe','c:\Git-2.39.0-64-bit.exe') ; \
Start-Process c:\Git-2.39.0-64-bit.exe -ArgumentList '/LOADINF=""C:\install-git-instructions.txt"" /SILENT' -Wait ;\
Remove-Item c:\Git-2.39.0-64-bit.exe -Force;\
# Example Contents for install-git-instructions.txt
#[Setup]
#Lang=default
#Dir=C:\Program Files\Git
#Group=Git
#NoIcons=0
#SetupType=default
#Components=gitlfs
#Tasks=
#PathOption=Cmd
#SSHOption=OpenSSH
#CURLOption=OpenSSL
#CRLFOption=CRLFAlways
#BashTerminalOption=MinTTY
#PerformanceTweaksFSCache=Enabled
#UseCredentialManager=Disabled
#EnableSymlinks=Disabled
winget tool Install winget tool 아직 없으면 install winget tool을 사용하여 명령 프롬프트 또는 Powershell에 이 명령을 입력합니다.
winget install --id Git.Git -e --source winget
언급URL : https://stackoverflow.com/questions/46731433/how-to-download-and-install-git-client-for-window-using-powershell
'programing' 카테고리의 다른 글
GDB - 별도창에 대상어플리케이션 출력 표시 (0) | 2023.09.13 |
---|---|
Wordpress - 비밀번호 변경 시 사용자 알림 비활성화 (0) | 2023.09.13 |
PDO 거짓 양의 교착 상태 (0) | 2023.09.13 |
매개변수로서의 기능 전달 (0) | 2023.09.13 |
MySQL 개념: 세션 vs 연결 (0) | 2023.09.13 |