← 가이드 목록으로 ← Back to guides

Git 대규모 팀 워크플로우와 자동화 완벽 가이드 Git Large Team Workflow & Automation Complete Guide

대규모 프로젝트에서는 Git Submodules로 의존성을 관리하고, Worktree로 병렬 작업하며, Hooks로 워크플로우를 자동화합니다.

In large projects, manage dependencies with Git Submodules, work in parallel with Worktree, and automate workflows with Hooks.

Git Submodules Git Submodules

Submodules는 다른 Git 저장소를 현재 저장소의 하위 디렉토리로 포함합니다. 공통 라이브러리나 마이크로서비스 관리에 유용합니다.

Submodules include other Git repositories as subdirectories of the current repository. Useful for managing common libraries or microservices.

# 서브모듈 추가
$ git submodule add https://github.com/lib/common.git libs/common

# 서브모듈 포함하여 클론
$ git clone --recursive https://github.com/myrepo.git

# 기존 저장소의 서브모듈 초기화
$ git submodule update --init --recursive

# 서브모듈 업데이트
$ git submodule update --remote
# Add submodule
$ git submodule add https://github.com/lib/common.git libs/common

# Clone with submodules
$ git clone --recursive https://github.com/myrepo.git

# Initialize submodules in existing repo
$ git submodule update --init --recursive

# Update submodules
$ git submodule update --remote

Git Worktree Git Worktree

Worktree를 사용하면 하나의 저장소에서 여러 브랜치를 동시에 체크아웃할 수 있습니다. 핫픽스와 기능 개발을 병렬로 진행하세요.

Worktree allows you to checkout multiple branches simultaneously in one repository. Work on hotfixes and feature development in parallel.

# 새 워크트리 생성 (별도 디렉토리에 브랜치 체크아웃)
$ git worktree add ../hotfix-branch hotfix/urgent

# 워크트리 목록 확인
$ git worktree list

# 워크트리 제거
$ git worktree remove ../hotfix-branch

# 정리 (삭제된 워크트리 참조 제거)
$ git worktree prune
# Create new worktree (checkout branch in separate directory)
$ git worktree add ../hotfix-branch hotfix/urgent

# List worktrees
$ git worktree list

# Remove worktree
$ git worktree remove ../hotfix-branch

# Prune (remove deleted worktree references)
$ git worktree prune

Git Hooks 자동화 Git Hooks Automation

Git Hooks는 커밋, 푸시 등의 이벤트에서 스크립트를 자동 실행합니다. 코드 품질과 팀 규칙을 강제할 수 있습니다.

Git Hooks automatically run scripts on events like commit or push. Enforce code quality and team rules.

# .git/hooks/pre-commit (커밋 전 린트 실행)
#!/bin/sh
npm run lint
if [ $? -ne 0 ]; then
  echo "Lint 에러! 커밋이 거부되었습니다."
  exit 1
fi
# .git/hooks/commit-msg (커밋 메시지 규칙 검증)
#!/bin/sh
if ! grep -qE "^(feat|fix|docs|style|refactor|test|chore):" "$1"; then
  echo "커밋 메시지가 Conventional Commits 규칙을 따르지 않습니다."
  exit 1
fi
# .git/hooks/pre-commit (run lint before commit)
#!/bin/sh
npm run lint
if [ $? -ne 0 ]; then
  echo "Lint failed! Commit rejected."
  exit 1
fi

🎣 주요 Git Hooks 🎣 Main Git Hooks

  • pre-commit: 커밋 전 (린트, 포맷 검사)
  • commit-msg: 커밋 메시지 검증
  • pre-push: 푸시 전 (테스트 실행)
  • post-merge: 병합 후 (의존성 설치)
  • pre-commit: Before commit (lint, format check)
  • commit-msg: Commit message validation
  • pre-push: Before push (run tests)
  • post-merge: After merge (install dependencies)

💡 Husky로 Hooks 관리하기 💡 Managing Hooks with Husky

$ npx husky-init && npm install
$ npx husky add .husky/pre-commit "npm run lint"

Husky를 사용하면 Hooks를 버전 관리하고 팀과 공유할 수 있습니다.

Husky allows you to version control hooks and share with the team.

⚠️ Submodules 주의사항 ⚠️ Submodules Cautions

  • 서브모듈 변경 후 부모 저장소도 커밋 필요
  • --recursive 없이 클론하면 서브모듈이 비어있음
  • 복잡한 의존성에는 Git LFS나 패키지 매니저 고려
  • After submodule changes, parent repo commit is also needed
  • Cloning without --recursive leaves submodules empty
  • Consider Git LFS or package managers for complex dependencies