Branch 관련 명령어

✒️ 2025-07-26 20:57 내용 수정


Branch 확인

1. Branch 목록 보기

git branch
git branch -r
git branch -a

2. 원격 Branch 내용 동기화

git fetch
git fetch --prune
git remote prune origin

3. 현재 Branch 확인

git branch --show-current

Branch 변경

git checkout <Branch이름>
git switch <Branch이름>
git switch -

Branch 이름 변경

git branch -m <변경할Branch이름> <새Branch이름>

Branch 생성

1. Branch 생성

git branch <Branch이름>
git branch feature/login
git branch <Branch이름> <원본Branch이름>

2. Branch 생성 + 전환 (checkout)

git checkout -b <Branch이름>
git checkout -b feature/login
git switch -c <Branch이름>

3. 원격에 있는 Branch를 로컬에 가져와 Branch 생성하기

git checkout -t origin/<Branch이름>

4. 원격 Branch 기반으로 Branch 생성

git checkout -b <새로운Branch이름> origin/<기존Branch이름>
git checkout -b feature/login origin/develop

5. 생성한 Branch 업로드

git push
git push -u origin <Branch이름>
git push origin master -f

Branch 병합 (Merge vs Rebase)

1. Merge

git merge feature
git merge <병합할 Branch이름>
git pull origin <병합할 Branch> --allow-unrelated-histories

2. Rebase

git rebase newbranch

Branch 삭제

1. 로컬 Branch 삭제

git branch -d <Branch이름>
git branch -D <Branch이름>

2. 원격 Branch 삭제

git push origin --delete <Branch이름>