30일 만에 마스터하는 Git 버전 관리

Day 28: GitHub 포크와 풀 리퀘스트 워크플로 이해하기

포크와 풀 리퀘스트는 GitHub 오픈 소스 협업의 기본입니다. 이 글에서는 쓰기 권한이 없는 프로젝트에 기여하는 방법을 설명하겠습니다.

포크 이해하기

포크는 여러분의 GitHub 계정 아래에 있는 리포지토리의 완전한 복사본입니다. 포크를 이용하면 다음을 할 수 있습니다.

  • 원본 프로젝트에 영향을 주지 않고 자유롭게 실험할 수 있습니다
  • 풀 리퀘스트로 변경 사항을 제안할 수 있습니다
  • 프로젝트를 필요에 맞게 커스터마이징할 수 있습니다

Fork vs Clone vs Branch

  • Fork: GitHub에서 리포지토리를 복사합니다(여러분의 계정)
  • Clone: 리포지토리를 로컬 컴퓨터에 복사합니다
  • Branch: 분기되는 개발 라인을 만듭니다

리포지토리 Fork하기

GitHub에서

  1. 리포지토리로 이동합니다
  2. “Fork” 버튼을 클릭합니다(오른쪽 상단)
  3. 포크할 위치를 선택합니다(여러분의 계정 또는 조직)
  4. GitHub가 포크를 만들 때까지 기다립니다

포크 Clone하기

# Clone your fork
git clone https://github.com/your-username/repo-name.git

# Navigate to directory
cd repo-name

# Add upstream remote
git remote add upstream https://github.com/original-owner/repo-name.git

# Verify remotes
git remote -v
# origin    https://github.com/your-username/repo-name.git (fetch)
# origin    https://github.com/your-username/repo-name.git (push)
# upstream  https://github.com/original-owner/repo-name.git (fetch)
# upstream  https://github.com/original-owner/repo-name.git (push)

완전한 풀 리퀘스트 워크플로

1단계: 포크 동기화하기

# Fetch upstream changes
git fetch upstream

# Checkout your main branch
git checkout main

# Merge upstream changes
git merge upstream/main

# Push to your fork
git push origin main

2단계: 기능 브랜치 만들기

# Create and checkout feature branch
git checkout -b fix-typo-in-readme

# Make your changes
# Edit files...

# Stage changes
git add README.md

# Commit changes
git commit -m "Fix typo in installation instructions"

3단계: 포크에 Push하기

# Push branch to your fork
git push origin fix-typo-in-readme

4단계: 풀 리퀘스트 만들기

  1. GitHub에서 여러분의 포크로 이동합니다
  2. “Compare & pull request” 버튼을 클릭합니다
  3. PR 세부 정보를 입력합니다.
    • Title: 명확하고 간결한 설명
    • Description: 무엇을, 왜, 어떻게
    • 해당하면 이슈를 참조합니다
  4. “Create pull request”를 클릭합니다

5단계: 피드백에 응답하기

# Make requested changes
# Edit files...

# Commit changes
git add .
git commit -m "Address review feedback"

# Push updates
git push origin fix-typo-in-readme
# PR automatically updates!

6단계: 병합 후

# Switch to main
git checkout main

# Pull merged changes
git pull upstream main

# Push to your fork
git push origin main

# Delete feature branch
git branch -d fix-typo-in-readme
git push origin --delete fix-typo-in-readme

Fork를 최신 상태로 유지하기

정기 동기화

# Fetch and merge in one command
git checkout main
git pull upstream main
git push origin main

자동 동기화

포크 페이지에서 GitHub의 “Fetch upstream” 버튼을 사용하거나 GitHub Actions를 설정합니다.

# .github/workflows/sync-upstream.yml
name: Sync Fork
on:
  schedule:
    - cron: '0 0 * * *'  # Daily
  workflow_dispatch:
jobs:
  sync:
    runs-on: ubuntu-latest
    steps:
      - uses: TobKed/github-forks-sync-action@v1
        with:
          upstream: original-owner/repo-name
          target: your-username/repo-name

하나의 PR에 여러 커밋 넣기

방법 1: 대화형 Rebase

# Squash commits
git rebase -i HEAD~3

# In editor, change 'pick' to 'squash' for commits to combine
# Save and edit commit message

# Force push (since you're rewriting history)
git push -f origin feature-branch

방법 2: Soft Reset

# Reset to before your commits
git reset --soft HEAD~3

# Create single commit
git commit -m "Complete feature implementation"

# Force push
git push -f origin feature-branch

PR의 병합 충돌 처리하기

# Sync with upstream
git fetch upstream

# Rebase on upstream/main
git rebase upstream/main

# Resolve conflicts
# Edit conflicting files
git add resolved-files
git rebase --continue

# Force push
git push -f origin feature-branch

Draft 풀 리퀘스트

조기 피드백을 위해 draft PR을 만듭니다.

  1. PR을 만들 때 “Create pull request”의 드롭다운을 클릭합니다
  2. “Create draft pull request”를 선택합니다
  3. 완료되면 준비 완료로 표시합니다

장점은 다음과 같습니다.

  • 조기 피드백을 받을 수 있습니다
  • 진행 중인 작업을 보여 줄 수 있습니다
  • 실수로 병합되는 것을 방지합니다

풀 리퀘스트 모범 사례

PR을 만들기 전에

  • 코드가 동작하고 테스트되었습니다
  • 프로젝트 스타일 가이드라인을 따릅니다
  • 문서가 업데이트되었습니다
  • 커밋이 깔끔하고 논리적입니다
  • 브랜치가 main과 최신 상태입니다

좋은 PR 작성하기

제목:

❌ Fix stuff
✅ Fix null pointer exception in user login

설명:

## What
Fixes a null pointer exception that occurs when users login with empty passwords.

## Why
Bug #123 reported crashes on invalid login attempts.

## How
Added null check before password validation.

## Testing
- Tested with empty password
- Tested with valid password
- Tested with invalid password

Closes #123

리뷰 중에는

  • 모든 댓글에 응답하세요
  • 불명확하면 질문하세요
  • 요청된 변경 사항을 신속히 반영하세요
  • 제안에 열려 있으세요
  • 리뷰어에게 감사하세요

오픈 소스에 기여하기

프로젝트 찾기

  1. GitHub Explore: https://github.com/explore
  2. First Timers Only: https://www.firsttimersonly.com/
  3. Good First Issue: GitHub에서 검색하세요
  4. Up For Grabs: https://up-for-grabs.net/

기여하기 전에

  1. CONTRIBUTING.md를 읽으세요
  2. 열려 있는 이슈를 확인하세요
  3. 기존 PR을 살펴보세요
  4. 행동 강령을 이해하세요
  5. 개발 환경을 설정하세요

첫 번째 PR

작게 시작하세요.

  • 오타 수정
  • 문서 개선
  • 테스트 추가
  • 명백한 버그 수정

평판 쌓기

  1. 문서부터 시작하세요
  2. 좋은 버그를 보고하세요
  3. 이슈에서 다른 사람을 도우세요
  4. 품질 좋은 PR을 제출하세요
  5. 인내심을 갖고 존중하세요

피해야 할 흔한 실수

  1. 포크를 동기화하지 않기: PR을 만들기 전에 항상 업데이트하세요
  2. 변경 사항이 너무 많기: PR을 집중적으로 유지하세요
  3. 설명이 없기: 무엇을, 왜 했는지 설명하세요
  4. main에 강제 push: 절대로 하지 마세요
  5. 메인테이너와 논쟁하기: 존중하세요
  6. 테스트하지 않기: 변경 사항을 항상 테스트하세요

오늘의 요약

포크와 풀 리퀘스트는 대규모 오픈 소스 협업을 가능하게 합니다. 이 워크플로를 이해하면 기여할 수 있는 수천 개의 프로젝트가 열립니다. 작게 시작하고, 인내심을 가지며, 경험 많은 기여자도 한때는 초보자였다는 것을 기억하세요.

오늘 배운 Git 명령어와 매개변수를 다시 정리하겠습니다.

  • git clone
  • git remote add upstream
  • git fetch upstream
  • git merge upstream/main
  • git push origin branch-name
  • git push -f origin branch-name
  • git rebase -i HEAD~n
  • git reset –soft HEAD~n