[클로드 코드] (6) 깃헙 연동

깃헙과의 통합은 클로드 코드의 핵심 기능이에요. 이 글에서는 리포지토리 접근, 코드 리뷰, PR 생성, 이슈 관리 등 깃헙 연동 등을 배우며, 소스 코드 관리 워크플로우를 자동화하는 방식을 다루고 있어요.

검은 배경에 픽셀 스타일 CLAUDE CODE 로고와 "클로드 코드 (6) 깃헙 어눙" 제목이 있는 썸네일 이미지.

깃헙(GitHub)과의 통합은 클로드 코드가 코드 저장소를 직접 관리하고, 협업 워크플로우를 자동화할 수 있게 해줍니다. 리포지토리 접근부터 PR 생성, 코드 리뷰, 이슈 관리까지 깃헙 연동의 모든 측면을 배우고, 개발 효율을 극대화하며, 팀과의 협업을 더욱 매끄럽게 만들어 보세요.

1. GitHub 연동의 중요성

Claude Code와 GitHub를 연동하면 다음과 같은 작업이 가능합니다:

2. GitHub 연동 설정

1단계: GitHub 토큰 생성

GitHub Personal Access Token을 생성해야 합니다.

GitHub 웹사이트에서:
1. Settings > Developer settings > Personal access tokens
2. Generate new token (classic)
3. 필요한 권한 선택:
repo – 저장소 접근
workflow – GitHub Actions
read:user – 사용자 정보 읽기

2단계: CLAUDE.md에 토큰 설정

# GitHub Configuration

## GitHub MCP
github:
  token: ${GITHUB_TOKEN}
  username: your-username
  timeout: 30s
  cache: true

3단계: 환경 변수 설정

# .env 파일에 저장
export GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

# 또는 시스템 환경 변수로 설정
export GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

3. GitHub 저장소 작업

저장소 클론

claude git clone https://github.com/username/repo.git

또는 CLAUDE.md에서:

# Repository Configuration

## Primary Repository
repository_url: https://github.com/username/repo.git
repository_branch: main
auto_pull: true

저장소 정보 조회

claude git info

# 출력:
# Repository: username/repo
# URL: https://github.com/username/repo.git
# Branch: main
# Commits: 245
# Last Update: 2 hours ago

4. 브랜치 관리

브랜치 생성

claude git branch create feature/new-feature

CLAUDE.md 설정:

## Branch Configuration

# 자동으로 생성할 브랜치 템플릿
branch_templates:
  - feature/{feature-name}
  - bugfix/{bug-description}
  - docs/{doc-title}

브랜치 전환

claude git branch switch main
claude git branch switch develop

브랜치 목록 조회

claude git branch list

# 출력:
# Local Branches:
# * main
#   develop
#   feature/auth
#   bugfix/performance

5. 커밋 및 푸시

자동 커밋

claude git commit "Add user authentication module"

자동 커밋 옵션:

## Git Configuration

git:
  auto_commit: true
  commit_template: |
    {title}

    {body}

    Fixes: #{issue_number}
  commit_timeout: 60s

커밋 메시지 규칙

Claude Code는 Conventional Commits를 지원합니다:

# feat: 새로운 기능
claude git commit "feat: add login validation"

# fix: 버그 수정
claude git commit "fix: resolve infinite loop in parser"

# docs: 문서 변경
claude git commit "docs: update API documentation"

# refactor: 코드 리팩토링
claude git commit "refactor: simplify database queries"

# test: 테스트 추가/수정
claude git commit "test: add unit tests for auth module"

# chore: 빌드/도구/의존성 변경
claude git commit "chore: update dependencies"

자동 푸시

claude git push origin main

CLAUDE.md 설정:

git:
  auto_push: true
  push_timeout: 60s
  verify_before_push: true

6. Pull Request 관리

Pull Request 생성

claude git pr create \
  --title "Add authentication module" \
  --body "Implements JWT-based authentication" \
  --target main

Pull Request 템플릿

## Pull Request Template

# Description
{description}

## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update

## Checklist
- [ ] Tests pass
- [ ] Code follows style guidelines
- [ ] Documentation updated
- [ ] No breaking changes

Pull Request 확인

claude git pr list
claude git pr view {pr-number}
claude git pr merge {pr-number}

7. Issue 관리

Issue 생성

claude git issue create \
  --title "Bug: Login fails on Safari" \
  --body "Users cannot log in using Safari browser" \
  --labels "bug,high-priority"

Issue 연결

커밋 메시지에 Issue 번호 포함:

claude git commit "Fix login validation #123"

자동으로 Issue #123에 커밋이 연결됩니다.

Issue 자동 클로징

Pull Request 설명에 포함:

Fixes #123
Closes #456

병합 시 자동으로 Issue가 닫힙니다.

8. GitHub Actions 연동

Actions 상태 확인

claude git actions status

Actions 트리거

claude git actions trigger workflow.yml

Actions 로그 확인

claude git actions logs --workflow build --latest

9. 협업 워크플로우

기본 워크플로우

# 1. 최신 코드 받기
claude git pull origin main

# 2. 브랜치 생성
claude git branch create feature/new-feature

# 3. 코드 작성 및 커밋
claude code "Add new feature"
claude git commit "feat: implement new feature"

# 4. Push
claude git push origin feature/new-feature

# 5. Pull Request 생성
claude git pr create --title "Add new feature"

CLAUDE.md 자동화:

## Workflow Automation

workflows:
  feature_development:
    - git pull origin main
    - git branch create feature/{feature-name}
    - code implementation
    - git commit "feat: {feature-name}"
    - git push origin feature/{feature-name}
    - git pr create --title "Add {feature-name}"

10. 코드 리뷰 준비

품질 검사

# 린트 실행
claude bash "npm run lint"

# 테스트 실행
claude bash "npm test"

# 빌드 확인
claude bash "npm run build"

자동 검사 설정:

## Quality Checks

quality_checks:
  before_push:
    - lint
    - test
    - build
  before_pr:
    - coverage
    - security_scan

11. GitHub 보안 설정

토큰 보안

# ✓ 좋음: 환경 변수 사용
export GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

# ❌ 나쁨: 파일에 직접 입력
github_token: ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx  # 커밋하면 위험!

민감한 정보 제거

# 토큰이 포함된 커밋 히스토리 제거
claude git secret-scan

12. GitHub 고급 기능

코드 리뷰 자동화

## Automated Code Review

code_review:
  enabled: true
  check_for:
    - code_style
    - security_issues
    - performance_problems
    - test_coverage

자동 라벨링

## Automatic Labeling

auto_labels:
  - pattern: "^feat:"
    labels: ["enhancement"]
  - pattern: "^fix:"
    labels: ["bug"]
  - pattern: "^docs:"
    labels: ["documentation"]

릴리스 자동화

claude git release create v1.0.0 \
  --notes "First stable release"

13. 트러블슈팅

인증 실패

# 토큰 확인
echo $GITHUB_TOKEN

# 토큰 갱신
claude auth refresh github

# 재로그인
claude auth login github

푸시 거부

# 원격 저장소 최신 상태 동기화
claude git pull origin main
claude git push origin main

머지 충돌

# 충돌 확인
claude git status

# 충돌 해결 후 커밋
claude git commit "Resolve merge conflicts"

 

클로드 코드 시리즈

(1) 클로드 코드와 클로드 코드의 작동 방식

(2) 내장 도구와 MCP 작동 방식

(3) 기본 사용법 및 설정

(4) 커맨드(명령어, Command)

(5) MCP 연결과 권한 설정

(6) 깃헙 연동

(7) 훅의 정의

(8) 훅 생성 및 실행 방법

(9) 클로드 코드 SDK 설치법

클로드 코드 시리즈

(1) 클로드 코드와 클로드 코드의 작동 방식

(2) 내장 도구와 MCP 작동 방식

(3) 기본 사용법 및 설정

(4) 커맨드(명령어, Command)

(5) MCP 연결과 권한 설정

(6) 깃헙 연동

(7) 훅의 정의

(8) 훅 생성 및 실행 방법

(9) 클로드 코드 SDK 설치법