Notice
Recent Posts
250x250
«   2026/04   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30
관리 메뉴

일상 코딩

[윈도우 개발 환경 설정] 2편: Git & GitHub 설정 본문

Windows 개발환경 세팅

[윈도우 개발 환경 설정] 2편: Git & GitHub 설정

polarcompass 2026. 3. 31. 22:22
728x90

2편: Git & GitHub 설정

시리즈: 윈도우 네이티브 개발 환경 구축 A to Z (2/14)
환경: Windows 11, PowerShell 7, Windows Terminal


서론

1편에서 터미널과 패키지 매니저를 세팅했으니, 이제 모든 개발의 출발점인 버전 관리를 준비할 차례입니다. 2편에서는 Git for Windows 설치부터 GitHub SSH 인증, GitHub CLI 로그인까지 마무리합니다. 이 편이 끝나면 PowerShell에서 git pushgh 명령어를 바로 사용할 수 있게 됩니다.


1. Git for Windows 설치

winget install --id Git.Git --source winget --accept-package-agreements --accept-source-agreements

설치 후 터미널을 재시작하고 버전을 확인합니다.

git --version
# git version 2.x.x.windows.x

2. 글로벌 .gitconfig 설정

커밋에 남을 이름과 이메일을 등록하고, 윈도우 개발 시 필수적인 줄바꿈 설정을 잡아 줍니다.

# 사용자 정보 — 본인 정보로 변경하세요
git config --global user.name "Your Name"
git config --global user.email "you@example.com"

# 줄바꿈: 체크아웃 시 CRLF, 커밋 시 LF로 변환
git config --global core.autocrlf true

# 기본 브랜치명
git config --global init.defaultBranch main

# 기본 에디터 (3편에서 설치할 Antigravity 경로)
git config --global core.editor "antigravity --wait"

# pull 전략: rebase 기본값
git config --global pull.rebase true

설정 전체를 확인하려면 아래 명령어를 사용합니다.

git config --global --list

3. SSH 키 생성 & GitHub 등록

HTTPS 대신 SSH로 GitHub에 연결하면 매번 비밀번호를 입력할 필요가 없습니다.

3-1. 키 생성

ssh-keygen -t ed25519 -C "you@example.com"

경로는 기본값(C:\Users\<사용자>\.ssh\id_ed25519)을 그대로 엔터로 넘기고, 패스프레이즈는 입력하거나 빈 칸으로 두어도 됩니다.

3-2. SSH Agent 등록

Windows에는 OpenSSH Authentication Agent 서비스가 기본 포함되어 있지만 비활성 상태일 수 있습니다. 관리자 권한 PowerShell에서 실행합니다.

# 서비스 시작 유형을 자동으로 변경하고 시작
Set-Service ssh-agent -StartupType Automatic
Start-Service ssh-agent

이후 일반 PowerShell에서 키를 등록합니다.

ssh-add "$env:USERPROFILE\.ssh\id_ed25519"

3-3. 공개 키 복사

Get-Content "$env:USERPROFILE\.ssh\id_ed25519.pub" | Set-Clipboard

클립보드에 복사된 상태입니다.

3-4. GitHub에 등록

  1. github.com/settings/keys 접속
  2. New SSH key 클릭
  3. Title에 알아볼 수 있는 이름(예: Windows-Dev-2026) 입력
  4. Key 영역에 붙여넣기(Ctrl+V) 후 Add SSH key

3-5. 연결 테스트

ssh -T git@github.com
Hi <username>! You've successfully authenticated, but GitHub does not provide shell access.

이 메시지가 나오면 성공입니다.


4. GPG 서명 (선택)

GitHub 커밋에 Verified 뱃지를 달고 싶다면 GPG 서명을 설정합니다. 필수는 아니므로 건너뛰어도 됩니다.

4-1. GPG 설치

winget install --id GnuPG.GnuPG --source winget --accept-package-agreements --accept-source-agreements

터미널을 재시작합니다.

4-2. GPG 키 생성

gpg --full-generate-key

선택지가 나오면 아래와 같이 입력합니다.

  • 종류: 1 (RSA and RSA)
  • 키 크기: 4096
  • 유효 기간: 0 (무기한) 또는 원하는 기간
  • 이름/이메일: Git에 설정한 것과 동일하게

4-3. 키 ID 확인

gpg --list-secret-keys --keyid-format=long

출력에서 sec rsa4096/ 뒤에 오는 16자리 문자열이 키 ID입니다.

sec   rsa4096/AAAAAAAABBBBBBBB 2026-03-31 [SC]

4-4. Git에 GPG 서명 등록

git config --global user.signingkey AAAAAAAABBBBBBBB
git config --global commit.gpgsign true
git config --global gpg.program "C:\Program Files (x86)\GnuPG\bin\gpg.exe"

GPG 설치 경로가 다를 수 있습니다. where.exe gpg 명령어로 실제 경로를 확인하세요.

4-5. GitHub에 GPG 공개 키 등록

gpg --armor --export AAAAAAAABBBBBBBB | Set-Clipboard

github.com/settings/keysNew GPG key → 붙여넣기 → Add GPG key


5. GitHub CLI (gh) 설치 & 인증

GitHub CLI를 사용하면 PR 생성, 이슈 관리, 레포 생성 등을 터미널에서 바로 처리할 수 있습니다.

5-1. 설치

winget install --id GitHub.cli --source winget --accept-package-agreements --accept-source-agreements

터미널을 재시작합니다.

gh --version

5-2. 인증

gh auth login

대화형 프롬프트가 나타납니다. 아래와 같이 선택합니다.

? Where do you use GitHub?  →  GitHub.com
? What is your preferred protocol for Git operations?  →  SSH
? Upload your SSH public key to your GitHub account?  →  (이미 등록했으면 Skip)
? How would you like to authenticate GitHub CLI?  →  Login with a web browser

브라우저에서 인증을 완료하면 CLI 로그인이 끝납니다.

# 인증 상태 확인
gh auth status

6. .gitignore_global 설정

프로젝트마다 .gitignore를 작성하지만, OS나 에디터가 만드는 파일은 글로벌로 한 번만 무시 처리해 두면 편합니다.

# 파일 생성
New-Item -ItemType File -Path "$env:USERPROFILE\.gitignore_global" -Force

아래 내용을 파일에 작성합니다.

@"
# ── OS ──
Thumbs.db
Desktop.ini
.DS_Store

# ── Editor ──
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.swp
*.swo

# ── Environment ──
.env
.env.local

# ── Python ──
__pycache__/
*.pyc

# ── Node ──
node_modules/

# ── Go ──
*.exe
*.dll
"@ | Set-Content -Path "$env:USERPROFILE\.gitignore_global" -Encoding UTF8

Git에 등록합니다.

git config --global core.excludesfile "$env:USERPROFILE\.gitignore_global"

최종 확인 체크리스트

# 1. Git 버전
git --version

# 2. 글로벌 설정
git config --global user.name
git config --global user.email
git config --global core.autocrlf
# → true

# 3. SSH 연결
ssh -T git@github.com
# → "Hi <username>! ..."

# 4. GitHub CLI
gh auth status
# → Logged in to github.com

# 5. 글로벌 gitignore
git config --global core.excludesfile
# → C:\Users\<사용자>\.gitignore_global

# 6. (선택) GPG
git config --global user.signingkey
# → 키 ID 출력

자동 세팅 스크립트

아래 내용을 setup-git.ps1로 저장하고 관리자 권한 PowerShell에서 실행하면, SSH 키 생성·GitHub 등록·gh 인증을 제외한 나머지를 한 번에 처리합니다.

SSH 키와 GitHub 인증은 사용자 입력이 반드시 필요하므로, 스크립트 마지막에 대화형 단계로 안내합니다.

#Requires -RunAsAdministrator
<#
.SYNOPSIS
    Git & GitHub 개발 환경 세팅 스크립트 (시리즈 2편)
.NOTES
    관리자 권한 PowerShell 7에서 실행하세요.
#>

param(
    [string]$GitUserName,
    [string]$GitUserEmail
)

$ErrorActionPreference = "Stop"

function Write-Step {
    param([string]$Message)
    Write-Host ""
    Write-Host "========================================" -ForegroundColor Cyan
    Write-Host "  $Message" -ForegroundColor Cyan
    Write-Host "========================================" -ForegroundColor Cyan
}

function Test-CommandExists {
    param([string]$Command)
    return [bool](Get-Command $Command -ErrorAction SilentlyContinue)
}

function Refresh-Path {
    $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" +
                [System.Environment]::GetEnvironmentVariable("Path", "User")
}

# ──────────────────────────────────────────────
# 사용자 정보 입력
# ──────────────────────────────────────────────
if (-not $GitUserName) {
    $GitUserName = Read-Host "Git 사용자 이름을 입력하세요"
}
if (-not $GitUserEmail) {
    $GitUserEmail = Read-Host "Git 이메일을 입력하세요"
}

# ──────────────────────────────────────────────
# 1. Git for Windows
# ──────────────────────────────────────────────
Write-Step "1/6 — Git for Windows 설치"

if (Test-CommandExists git) {
    Write-Host "  이미 설치됨: $(git --version)" -ForegroundColor Green
}
else {
    winget install --id Git.Git --source winget --accept-package-agreements --accept-source-agreements
    Refresh-Path
    Write-Host "  설치 완료" -ForegroundColor Green
}

# ──────────────────────────────────────────────
# 2. 글로벌 .gitconfig
# ──────────────────────────────────────────────
Write-Step "2/6 — 글로벌 Git 설정"

git config --global user.name "$GitUserName"
git config --global user.email "$GitUserEmail"
git config --global core.autocrlf true
git config --global init.defaultBranch main
git config --global core.editor "antigravity --wait"
git config --global pull.rebase true

Write-Host "  user.name  = $(git config --global user.name)" -ForegroundColor Green
Write-Host "  user.email = $(git config --global user.email)" -ForegroundColor Green
Write-Host "  autocrlf   = $(git config --global core.autocrlf)" -ForegroundColor Green

# ──────────────────────────────────────────────
# 3. GitHub CLI
# ──────────────────────────────────────────────
Write-Step "3/6 — GitHub CLI 설치"

if (Test-CommandExists gh) {
    Write-Host "  이미 설치됨: $(gh --version | Select-Object -First 1)" -ForegroundColor Green
}
else {
    winget install --id GitHub.cli --source winget --accept-package-agreements --accept-source-agreements
    Refresh-Path
    Write-Host "  설치 완료" -ForegroundColor Green
}

# ──────────────────────────────────────────────
# 4. SSH Agent 활성화
# ──────────────────────────────────────────────
Write-Step "4/6 — SSH Agent 활성화"

$sshAgentStatus = (Get-Service ssh-agent -ErrorAction SilentlyContinue).StartType
if ($sshAgentStatus -eq "Automatic") {
    Write-Host "  이미 Automatic 상태" -ForegroundColor Green
}
else {
    Set-Service ssh-agent -StartupType Automatic
    Write-Host "  StartupType → Automatic" -ForegroundColor Green
}

Start-Service ssh-agent -ErrorAction SilentlyContinue
Write-Host "  ssh-agent 실행 중" -ForegroundColor Green

# ──────────────────────────────────────────────
# 5. .gitignore_global
# ──────────────────────────────────────────────
Write-Step "5/6 — .gitignore_global 생성"

$ignorePath = "$env:USERPROFILE\.gitignore_global"

@"
# ── OS ──
Thumbs.db
Desktop.ini
.DS_Store

# ── Editor ──
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.swp
*.swo

# ── Environment ──
.env
.env.local

# ── Python ──
__pycache__/
*.pyc

# ── Node ──
node_modules/

# ── Go ──
*.exe
*.dll
"@ | Set-Content -Path $ignorePath -Encoding UTF8

git config --global core.excludesfile $ignorePath
Write-Host "  생성 완료: $ignorePath" -ForegroundColor Green

# ──────────────────────────────────────────────
# 6. SSH 키 생성 & GitHub 등록 (대화형)
# ──────────────────────────────────────────────
Write-Step "6/6 — SSH 키 & GitHub 인증 (대화형)"

$sshKeyPath = "$env:USERPROFILE\.ssh\id_ed25519"

if (Test-Path $sshKeyPath) {
    Write-Host "  SSH 키가 이미 존재합니다: $sshKeyPath" -ForegroundColor Yellow
    $overwrite = Read-Host "  새로 생성하시겠습니까? (y/N)"
    if ($overwrite -ne "y") {
        Write-Host "  기존 키를 유지합니다." -ForegroundColor Green
        ssh-add $sshKeyPath 2>$null
    }
    else {
        ssh-keygen -t ed25519 -C $GitUserEmail -f $sshKeyPath
        ssh-add $sshKeyPath
    }
}
else {
    Write-Host "  SSH 키를 생성합니다..."
    ssh-keygen -t ed25519 -C $GitUserEmail -f $sshKeyPath
    ssh-add $sshKeyPath
}

# 공개 키 클립보드 복사
$pubKey = Get-Content "$sshKeyPath.pub"
$pubKey | Set-Clipboard

Write-Host ""
Write-Host "  공개 키가 클립보드에 복사되었습니다." -ForegroundColor Magenta
Write-Host "  아래 페이지에서 'New SSH key'를 눌러 붙여넣으세요:" -ForegroundColor Magenta
Write-Host "  https://github.com/settings/keys" -ForegroundColor Yellow
Write-Host ""
Read-Host "  GitHub에 SSH 키를 등록한 뒤 Enter를 누르세요"

# SSH 연결 테스트
Write-Host "  SSH 연결 테스트 중..."
ssh -T git@github.com 2>&1 | ForEach-Object { Write-Host "  $_" -ForegroundColor Green }

# GitHub CLI 인증
Write-Host ""
Write-Host "  GitHub CLI 인증을 시작합니다." -ForegroundColor Magenta
Write-Host "  SSH → Login with a web browser 를 선택하세요." -ForegroundColor Magenta
Write-Host ""
gh auth login

# ──────────────────────────────────────────────
# 결과 요약
# ──────────────────────────────────────────────
Write-Host ""
Write-Host "========================================" -ForegroundColor Magenta
Write-Host "  Git & GitHub 세팅 완료!" -ForegroundColor Magenta
Write-Host "========================================" -ForegroundColor Magenta
Write-Host ""
Write-Host "[설치 결과 요약]" -ForegroundColor Cyan
Write-Host "  Git           : $(if (Test-CommandExists git) { git --version } else { 'MISSING' })"
Write-Host "  GitHub CLI    : $(if (Test-CommandExists gh) { (gh --version | Select-Object -First 1) } else { 'MISSING' })"
Write-Host "  user.name     : $(git config --global user.name)"
Write-Host "  user.email    : $(git config --global user.email)"
Write-Host "  autocrlf      : $(git config --global core.autocrlf)"
Write-Host "  SSH key       : $(if (Test-Path $sshKeyPath) { 'OK' } else { 'MISSING' })"
Write-Host "  gitignore     : $(git config --global core.excludesfile)"
Write-Host ""
Write-Host "[선택 사항]" -ForegroundColor Yellow
Write-Host "  GPG 서명을 설정하려면 블로그 본문의 '4. GPG 서명' 섹션을 참고하세요."
Write-Host ""

사용법

# 방법 1: 실행하면 이름/이메일을 대화형으로 물어봄
.\setup-git.ps1

# 방법 2: 파라미터로 바로 전달
.\setup-git.ps1 -GitUserName "Your Name" -GitUserEmail "you@example.com"

스크립트는 자동화할 수 있는 부분(Git 설치, 설정, CLI 설치, Agent, gitignore)을 먼저 처리한 뒤, SSH 키 생성과 GitHub 인증처럼 사용자 입력이 필요한 단계는 마지막에 대화형으로 안내합니다. GPG 서명은 선택 사항이므로 스크립트에 포함하지 않았고, 필요하면 본문을 따라 수동으로 진행하면 됩니다.


다음 편 예고

3편: Google Antigravity 설치 & 에디터 설정에서는 VS Code 포크인 Antigravity를 설치하고, 이 시리즈의 기술 스택에 맞는 확장 프로그램과 settings.json, 에이전트 모드 설정까지 한 번에 잡아 줍니다.

728x90