C.W.K.
Stream
Lesson 05 of 05 · published

Branch hygiene: 이름, 삭제, 정리

~16 min · branch, cleanup

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

branch 는 만들기도 지우기도 싸

Branch 위생 (hygiene) 은 1년 뒤에도 repo 를 읽을 만하게 만드는 housekeeping 이야. 원칙: 의식 없이 새 branch 만들고, 작업이 land 하면 지워. branch 200 개 묵힌 repo 는 잡동사니 서랍이고, 활성 12 개인 repo 는 workspace 야. 규모 무관 — 프로젝트, 팀, 개인 repo 다 이득.

이름 짓기가 비중 커. 대부분 팀이 prefix 기반 namespace 써: feature/, bugfix/, hotfix/, release/, chore/, experiment/. feature/short-summary 모양이 git branch -a 출력에서 잘 읽히고 도구에서 그룹화도 잘 돼. issue / 티켓 참조 있으면 추가: feature/142-oauth-github. my-changes, fix, test 같은 generic 이름 피해 — 충돌나고 정보 0.

삭제 두 가지. git branch -d feature/login 은 upstream 에 fully merge 된 경우에만 삭제 — Git 이 확인해줘. git branch -D 는 무조건 강제 삭제. 기본은 -d, merge 안 하고 일부러 버리는 branch 만 -D. local 삭제 후 remote 도 정리: git push origin --delete feature/login. GitHub 엔 PR-기반 workflow 용 'auto-delete head branches after merge' 설정도 있어.

Pruning 은 아무도 스케줄 안 하는데 다들 필요한 cleanup. 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 에 fully merge 된 local branch 표시, 삭제 후보 완벽. 가끔 돌리면 repo 가 읽을 만하게 남아.

Code

이름 짓기와 list·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

merged feature branch 적어도 하나 있는 repo 에서 git branch --merged main. merged branch 하나를 git branch -d 로 삭제 + 매칭되는 remote 도 git push origin --delete. global 에 fetch.prune = true 활성화. git for-each-ref --sort=-committerdate refs/heads/ 돌려서 age + merged 상태 기준으로 추가 삭제 후보 셋 식별.

Progress

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

댓글 0

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

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