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

작업 지저분한데 hotfix 들어올 때

~22 min · playbook, hotfix, worktree

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

반쯤 끝낸 작업 옆에서 hotfix하기

feature/profile-page에서 두 시간째 작업하는데 on-call channel에서 운영의 critical bug를 지금 고쳐 달라는 연락이 왔다고 해보자. 진행 중 작업을 억지로 commit하거나 잃어버리는 건 잘못된 대응이야. 올바른 routine은 작업을 안전하게 피신시키고, main에서 branch를 갈라 fix하고 ship한 뒤 돌아오는 거야. 연습돼 있다면 15분 안에도 가능해.

피신 방법은 둘이야. 작업이 작고 방해가 짧다면 stash를 써. git stash push -u -m "WIP: profile-page"가 staged, unstaged, untracked file을 저장하고 tree를 깨끗하게 해. hotfix가 30분 이상 걸리거나 feature를 다른 창에서 계속 열어두고 싶다면 worktree가 좋아. git worktree add ../repo-hotfix hotfix/login-crash main은 현재 feature를 흔들지 않고 병렬 checkout을 만들어.

Hotfix도 작은 변경의 규칙을 따라. main에서 branch를 만들고 명확한 message의 commit 하나로 fix한 뒤 push해. 긴급한 이유와 검증법을 쓴 PR을 열고 빠르게 review한 뒤 merge하고 배포해. 의식이 목적을 가로막는다면 불필요한 절차는 줄일 수 있지만, fix가 bug를 실제로 막는다는 test는 건너뛰지 마. 검증하지 않은 '될 것 같은' hotfix가 두 번째 outage를 만드는 길이야.

land와 배포 뒤에는 feature로 돌아와 hotfix가 든 main을 따라잡아야 해. git switch feature/profile-page하고 stash를 썼다면 git stash pop해. worktree였다면 cd ../처럼 원래 directory로 돌아와. 이어서 git fetch origingit rebase origin/main으로 feature를 최신 main 위에 올려. 같은 줄을 건드렸다면 여기서 conflict를 풀고 작업을 계속해.

Code

Stash 기반 hotfix 루틴·bash
# Feature 중간, hotfix 필요:
git stash push -u -m "WIP: profile-page (hotfix interrupt)"

# 최신 main 분기:
git fetch origin
git switch -c hotfix/login-crash origin/main

# 한 줄 fix, commit, push:
git add src/auth.js
git commit -m "fix(auth): handle null user_id in /login callback"
git push -u origin hotfix/login-crash

# gh 로 PR, 빠른 리뷰, merge, 배포:
gh pr create --base main --title "fix(auth): handle null user_id"
# (승인 + 체크 녹색 후)
gh pr merge --squash --delete-branch

# Feature 작업으로 복귀:
git switch feature/profile-page
git stash pop                       # WIP 복원

# Hotfix 된 main 따라잡기:
git fetch origin
git rebase origin/main
Worktree 기반 hotfix 루틴 (긴 방해엔 더 깔끔)·bash
# 현재 feature worktree 에서 stash 필요 없음:
cd ~/code/repo

# Hotfix branch 의 별도 worktree 추가:
git worktree add -b hotfix/login-crash ../repo-hotfix origin/main

# 새 worktree 에서 작업:
cd ../repo-hotfix
# ... fix 만들기 ...
git commit -am "fix(auth): ..."
git push -u origin hotfix/login-crash

# Merge + 배포 후 worktree 은퇴:
cd ~/code/repo
git worktree remove ../repo-hotfix

# Hotfix 를 feature branch 로 가져오기:
git fetch origin
git rebase origin/main

External links

Exercise

활성 프로젝트의 feature branch에 끝나지 않은 uncommitted 편집을 만든 뒤 hotfix routine을 연습해. stash하고 main에서 branch를 갈라 가짜 한 줄 fix를 commit, push, merge한 뒤 stash pop으로 feature에 돌아와 rebase해. 시간을 재고 worktree 방식으로도 반복해. 어느 쪽이 더 매끄러웠는지, 기본으로 무엇을 쓸지 적어봐.

Progress

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

댓글 0

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

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