한창 복잡한 기능을 구현하느라 코드 10여 군데를 고치고 아직 컴파일 에러도 해결하지 못한 상태인데, 갑자기 "운영 서버 결제 버그 났으니 hotfix 브랜치로 가서 1줄만 고쳐주세요!"라는 요청이 들어왔을 때, 프롬프트 상의 브랜치 표시(branch-name) $를 확인하며 안전하게 작업을 대피하고 복원하는 실무 사이클입니다.
1. 왜 git switch가 안 될까?
(feature/coupon-discount) $ git switch hotfix/urgent-bug
error: Your local changes to the following files would be overwritten by checkout:
app/Services/OrderService.php
Please commit your changes or stash them before you switch branches.
Aborting2. 실무 긴급 전환 4단계 사이클
Step 1. 작업 중인 내용 서랍에 숨기기
# 수정된 파일 + 새로 만든 파일까지 모두 메모를 붙여 서랍에 보관
(feature/coupon-discount) $ git stash push -u -m "WIP: 쿠폰 할인 로직 작성 중"
Saved working directory and index state On feature/coupon-discount: WIP: 쿠폰 할인 로직 작성 중
# Working Tree가 깨끗해진 상태 확인
(feature/coupon-discount) $ git statusStep 2. 긴급 브랜치로 이동하여 버그 수정 및 배포
(feature/coupon-discount) $ git switch hotfix/urgent-bug
Switched to branch 'hotfix/urgent-bug'
# 버그 1줄 수정 후 푸시
(hotfix/urgent-bug) $ git commit -am "fix: 결제 통신 타임아웃 예외 처리"
(hotfix/urgent-bug) $ git push origin hotfix/urgent-bugStep 3. 원래 내 개발 브랜치로 복귀
(hotfix/urgent-bug) $ git switch feature/coupon-discount
Switched to branch 'feature/coupon-discount'Step 4. 서랍에서 작업 꺼내와서 이어서 개발하기
# 가장 최근에 넣어둔 스태시를 꺼내 복원하고 서랍에서 삭제
(feature/coupon-discount) $ git stash pop
Auto-merging app/Services/OrderService.php
Dropped refs/stash@{0}
# 작업이 온전히 복원됨
(feature/coupon-discount) $ git status