본문 바로가기
C.W.K.
Stream
Lesson 05 of 05 · published

Branch hygiene: 이름, 삭제, 정리

~16 min · branch, cleanup

Level 0추적 전 새싹
0 XP0/47 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

branch는 만들기도 지우기도 값싸

Branch hygiene는 1년 뒤에도 repo를 읽을 만하게 유지하는 정리 습관이야. 원칙은 간단해. 새 branch는 부담 없이 만들고 작업이 land하면 지워. 묵은 branch가 200개인 repo는 잡동사니 서랍이고, 활성 branch가 12개인 repo는 작업 공간이야. 규모나 팀 여부와 상관없이 효과가 있어.

이름이 큰 몫을 해. 많은 팀이 feature/, bugfix/, hotfix/, release/, chore/, experiment/ 같은 prefix namespace를 써. feature/short-summary 형식은 git branch -a에서도 잘 읽히고 도구가 묶어 보여주기도 좋아. issue나 ticket이 있다면 feature/142-oauth-github처럼 붙여. my-changes, fix, test 같은 막연한 이름은 충돌하기 쉽고 주는 정보도 없어.

삭제에는 두 방식이 있어. git branch -d feature/login은 upstream에 완전히 merge됐을 때만 삭제하므로 Git이 안전을 확인해줘. git branch -D는 조건 없이 강제로 삭제해. 평소에는 -d를 쓰고, merge하지 않은 채 의도적으로 버릴 branch에만 -D를 써. local branch를 지운 뒤에는 git push origin --delete feature/login으로 remote도 정리해. GitHub에는 PR merge 뒤 head branch를 자동 삭제하는 설정도 있어.

Pruning은 아무도 일정에 넣지 않지만 모두에게 필요한 정리야. git remote prune origin은 origin에서 사라진 upstream branch의 remote-tracking ref를 없애. git fetch --prune은 보통 fetch하면서 같은 일을 해. git config --global fetch.prune true를 설정해두면 잊어도 돼. git branch --merged main은 main에 완전히 merge된 local branch를 보여주므로 삭제 후보를 찾기 좋아. 가끔 실행해 repo를 읽을 만하게 유지해.

Code

이름 짓기와 목록 보기·bash
# 흔한 namespace:
git switch -c feature/profile-page
git switch -c bugfix/login-crash
git switch -c hotfix/security-2026-04
git switch -c chore/update-deps
git switch -c experiment/new-rendering

# namespace 별 local + remote branch list:
git branch -a | sort

# 최근에 건드린 branch 부터 (stale 찾기 좋음):
git for-each-ref --sort=-committerdate refs/heads/ --format='%(refname:short)' | head -20
삭제 + prune·bash
# fully merge 된 local branch 삭제 (안전):
git branch -d feature/profile-page

# unmerged local 강제 삭제 (일부러 버림):
git branch -D experiment/dead-end

# remote 에서 삭제:
git push origin --delete feature/profile-page

# 매번 fetch 마다 죽은 remote-tracking ref 자동 prune:
git config --global fetch.prune true
git fetch                                   # 이제 prune 도 함
git remote prune origin                     # 명시적 prune

# main 에 이미 merge 된 local branch (삭제 후보):
git branch --merged main | grep -v '\* main'

External links

Exercise

merge된 feature branch가 적어도 하나 있는 repo에서 git branch --merged main을 실행해. merge된 branch 하나를 git branch -d로 지우고 해당 remote branch도 git push origin --delete로 정리해. global fetch.prune = true를 켠 뒤 git for-each-ref --sort=-committerdate refs/heads/를 실행해 오래된 정도와 merge 상태를 기준으로 추가 삭제 후보 셋을 골라봐.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.