🤝 GitHub 협업하기
📖 정의
GitHub 협업은 여러 개발자가 Git과 GitHub를 사용하여 동일한 프로젝트에서 효율적으로 함께 작업하는 방법입니다. **브랜치(Branch)**로 독립적인 작업 공간을 만들고, **Pull Request(PR)**로 코드 리뷰를 받으며, **이슈(Issue)**로 작업을 추적합니다. 충돌(Conflict)을 해결하고, 코드 품질을 유지하며, 팀과 원활하게 소통하는 것이 핵심입니다.
🎯 비유로 이해하기
공동 문서 작성
GitHub 협업을 Google Docs 공동 작업에 비유하면:
메인 브랜치 (main) = 최종 출판본
├─ 안정적이고 검증된 내용
└─ 항상 작동하는 상태 유지
기능 브랜치 (feature) = 개 인 초안
├─ 각자 자유롭게 작성
├─ 실험과 수정 가능
└─ 완성되면 제출
Pull Request = 편집 회의
├─ "이 부분 추가할게요"
├─ 동료들이 검토
├─ 피드백 반영
└─ 승인 후 최종본에 병합
이슈(Issue) = 할일 목록
├─ "3장 작성하기"
├─ "오타 수정"
└─ "참고 자료 추가"
레스토랑 주방
메인 브랜치 = 손님께 나가는 요리
├─ 완벽하게 완성된 상태
└─ 셰프의 최종 승인 필요
개발자 = 조리사
├─ 각자 담당 요리 준비
└─ 독립적인 작업대(브랜치) 사용
Pull Request = 맛보기
├─ 셰프가 맛 확인
├─ 다른 조리사 의견
└─ 최종 승인 후 서빙
코드 충돌 = 재료 겹침
├─ "둘 다 토마토 사용 중"
├─ 조율 필요
└─ 우선순위 결정
⚙️ 작동 원리
1. GitHub 협업 워크플로우
1. Issue 생성
└─ 작업 내용 정의
2. 브랜치 생성
└─ main에서 분기
3. 코드 작성
└─ 로컬에서 개발
4. 커밋 및 푸시
└─ 원격 브랜치에 업로드
5. Pull Request 생성
└─ 코드 리뷰 요청
6. 코드 리뷰
├─ 팀원들이 검토
├─ 코멘트 및 피드백
└─ 수정 요청
7. 피드백 반영
└─ 추가 커밋
8. 승인 및 병합
└─ main에 병합
9. 브랜치 삭제
└─ 정리
10. 최신 코드 동기화
└─ git pull
2. 브랜치 전략 (Git Flow)
main (또는 master)
├─ 프로덕션 배포용
├─ 항상 안정적
└─ 직접 커밋 금지
develop
├─ 개발용 메인 브랜치
├─ 다음 릴리스 준비
└─ feature 브랜치의 병합 대상
feature/* (기능 개발)
├─ feature/login
├─ feature/payment
└─ 개발 완료 후 develop에 병합
hotfix/* (긴급 수정)
├─ hotfix/security-patch
├─ main에서 분기
└─ main과 develop에 모두 병합
release/* (릴리스 준비)
├─ release/v1.0.0
├─ develop에서 분기
└─ 테스트 후 main에 병합
3. Pull Request 프로세스
개발자 A 팀원들 Reviewer
| | |
| 1. PR 생성 | |
|--------------------->| |
| | 2. 알림 받음 |
| |---------------------->|
| | | 3. 코드 리뷰
| | | (읽고 분석)
| | |
| | 4. 코멘트/수정 요청 |
|<----------------------------------------------|
| 5. 피드백 반영 | |
| 6. 추가 커밋 | |
|--------------------->| |
| | | 7. 재검토
| | |
| | 8. 승인 (Approve) |
|<----------------------------------------------|
| 9. Merge | |
|--------------------->| |
| | 10. 브랜 치 삭제 |
|--------------------->| |
💡 실제 예시
준비: 팀 프로젝트 시작
# 시나리오: 3명이 웹사이트를 함께 개발
# === 프로젝트 오너 (리더) ===
# 1. GitHub에서 새 저장소 생성
# - Repository name: team-project
# - Public
# - Add README
# - Add .gitignore (Node)
# - Choose license (MIT)
# 2. 로컬에 클론
git clone https://github.com/owner/team-project.git
cd team-project
# 3. 프로젝트 구조 생성
mkdir src tests docs
touch src/index.js src/app.js
touch README.md .gitignore
# 4. 초기 코드 작성
cat > src/index.js << 'EOF'
// Team Project
console.log('Hello, Team!');
EOF
# 5. 첫 커밋
git add .
git commit -m "Initial project setup"
git push origin main
# 6. 팀원 초대
# GitHub 웹사이트:
# Settings → Collaborators → Add people
# - developer1@email.com
# - developer2@email.com
# 초대 이메일 발송됨
Step 1: 팀원들 합류
# === 팀원 A (Developer 1) ===
# 1. 초대 수락
# 이메일에서 링크 클릭하여 수락
# 2. 저장소 클론
git clone https://github.com/owner/team-project.git
cd team-project
# 3. Git 설정 확인
git config user.name "Developer 1"
git config user.email "developer1@email.com"
# 4. 원격 저장소 확인
git remote -v
# origin https://github.com/owner/team-project.git (fetch)
# origin https://github.com/owner/team-project.git (push)
# 5. 브랜치 확인
git branch -a
# * main
# remotes/origin/main
# === 팀원 B (Developer 2) ===
# 동일한 과정 반복
Step 2: Issue로 작업 관리
# GitHub 웹사이트에서 Issue 생성
# === 프로젝트 오너 ===
# Issues 탭 → New issue
# Issue #1
Title: 사용자 로그인 기능 구현
Description:
사용자 로그인 기능을 구현합니다.
**요구사항:**
- [ ] 로그인 폼 UI
- [ ] 인증 로직
- [ ] 세션 관리
**기술스택:**
- React
- JWT
**담당자:** @developer1
**라벨:** enhancement, high priority
**마일스톤:** v1.0
# Issue #2
Title: 상품 목록 페이지 개발
Assignees: @developer2
Labels: feature, frontend
# Issue #3
Title: 데이터베이스 스키마 설계
Assignees: @owner
Labels: backend, database
# 팀원들에게 자동으로 알림 전송!
Step 3: 브랜치에서 작업하기
# === Developer 1: 로그인 기능 개발 ===
# 1. 최신 코드 받기
git checkout main
git pull origin main
# 2. 새 브랜치 생성 (Issue 번호 포함)
git checkout -b feature/login-1
# 브랜치 네이밍 규칙:
# - feature/기능명-이슈번호
# - bugfix/버그명-이슈번호
# - hotfix/긴급수정명
# 예: feature/login-1, bugfix/header-css-5
# 3. 코드 작성
src/Login.js 파일 생성:
```javascript
import React, { useState } from 'react';
function Login() {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const handleSubmit = async (e) => {
e.preventDefault();
try {
const response = await fetch('/api/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(\{ email, password \})
});
if (response.ok) {
const data = await response.json();
localStorage.setItem('token', data.token);
alert('로그인 성공!');
} else {
alert('로그인 실패');
}
} catch (error) {
console.error('Error:', error);
}
};
return (
<form onSubmit=\{handleSubmit\}>
<h2>로그인</h2>
<input
type="email"
placeholder="이메일"
value=\{email\}
onChange=\{(e) => setEmail(e.target.value)\}
required
/>
<input
type="password"
placeholder="비밀번호"
value=\{password\}
onChange=\{(e) => setPassword(e.target.value)\}
required
/>
<button type="submit">로그인</button>
</form>
);
}
export default Login;
4. 테스트 작성
tests/Login.test.js 파일 생성:
import { render, screen, fireEvent } from '@testing-library/react';
import Login from '../src/Login';
test('로그인 폼 렌더링', () => {
render(<Login />);
expect(screen.getByPlaceholderText('이메일')).toBeInTheDocument();
expect(screen.getByPlaceholderText('비밀번호')).toBeInTheDocument();
expect(screen.getByText('로그인')).toBeInTheDocument();
});
5. 로컬에서 테스트
npm test
6. 작은 단위로 자주 커밋 (권장!)
git add src/Login.js git commit -m "feat: 로그인 컴포넌트 UI 구현
- 이메일, 비밀번호 입력 폼 추가
- useState로 상태 관리
Related to #1"
7. 인증 로직 추가
... 코드 작성 ...
git add src/Login.js git commit -m "feat: 로그인 인증 API 연동
- fetch로 POST 요청
- JWT 토큰 localStorage 저장
- 에러 처리 추가
Related to #1"
8. 테스트 추가
git add tests/Login.test.js git commit -m "test: 로그인 컴포넌트 테스트 작성
Related to #1"
9. 원격에 푸시
git push origin feature/login-1
💡 팁: 커밋 메시지 규칙
feat: 새 기능
fix: 버그 수정
docs: 문서 변경
style: 코드 포매팅
refactor: 리팩토링
test: 테스트 추가
chore: 빌드, 설정 변경
### Step 4: Pull Request 생성
```bash
# === Developer 1 ===
# 1. GitHub 웹사이트에서 PR 생성
# - "Compare & pull request" 버튼 클릭 (자동으로 나타남)
# - 또는 Pull requests 탭 → New pull request
# 2. PR 정보 작성 (중요!)
Title: feat: 사용자 로그인 기능 구현
Description:
## 📝 변경사항
사용자 로그인 기능을 구현했습니다.
## ✨ 구현 내역
- [x] 로그인 폼 UI 구현
- [x] 이메일/비밀번호 입력 및 유효성 검사
- [x] API 연동 (POST /api/login)
- [x] JWT 토큰 저장
- [x] 에러 처리
- [x] 단위 테스트 작성
## 🧪 테스트
```bash
npm test
모든 테스트 통과 확인
📸 스크린샷
[로그인 화면 스크린샷 첨부]
🔗 관련 이슈
Closes #1
📋 체크리스트
- 코드 작동 확인
- 테스트 작성 및 통과
- 문서 업데이트
- 코드 스타일 준수
- 리뷰어 지정 필요