Git

초급 05. Branch 생성과 전환 실무 가이드

브랜치의 원리, 최신 git switch 명령어, 실무 브랜치 명명 규칙(feature/hotfix), 그리고 안전한 브랜치 삭제(-d vs -D) 방법

· 1min read · 86 views
초급 05. Branch 생성과 전환 실무 가이드

핵심 요약

최신 git switch를 활용한 브랜치 생성 및 전환, 실무 브랜치 명명 규칙, 머지된 브랜치와 미머지 브랜치의 안전한 삭제(-d vs -D) 가이드

브랜치(Branch)는 "독립된 평행 우주를 만드는 작업"입니다. 메인 코드베이스를 건드리지 않고 안전하게 새 기능을 실험하고 개발할 수 있는 핵심 메커니즘입니다. 이 문서는 프롬프트 상의 브랜치 표시(branch-name) $를 명시하여 최신 표준인 git switch를 기준으로 실무 브랜치 운영법을 다룹니다.


1. 최신 명령어: checkout 대신 switch를 쓰자

  • 브랜치 전환 / 생성: git switch 사용
  • 파일 변경 취소 / 복구: git restore 사용

2. 브랜치 생성 및 이동 기본 명령어

# 1. 로컬 및 원격 브랜치 전체 목록 확인
(main) $ git branch -a
* main
  remotes/origin/main
  remotes/origin/develop

# 2. 새로운 브랜치를 만들고 즉시 이동 (-c: create)
(main) $ git switch -c feature/shopping-cart
Switched to a new branch 'feature/shopping-cart'

# 프롬프트가 (feature/shopping-cart)로 바뀜
(feature/shopping-cart) $ git status

# 3. 기존에 있던 브랜치로 이동
(feature/shopping-cart) $ git switch develop
Switched to branch 'develop'

# 4. 직전에 머물렀던 이전 브랜치로 빠르게 되돌아가기
(develop) $ git switch -
Switched to branch 'feature/shopping-cart'
(feature/shopping-cart) $ 

3. 다 쓴 브랜치 삭제: -d vs -D의 차이

# develop 브랜치로 이동 후
(feature/shopping-cart) $ git switch develop
Switched to branch 'develop'

# 안전한 삭제 (-d: 이미 머지된 경우에만 삭제 허용)
(develop) $ git branch -d feature/shopping-cart
Deleted branch feature/shopping-cart (was 3a1f9b2).

# 머지되지 않은 실험 브랜치 강제 폐기 (-D)
(develop) $ git branch -D feature/abandoned-experiment
Deleted branch feature/abandoned-experiment.

Related Docs

Comments (0)

No comments yet. Be the first to comment!

Leave a Comment

로그인 후 댓글을 남길 수 있습니다.