본문 바로가기
Tool/Git

[Git] branch 관련 명령어 모음

by 챠챠12 2025. 6. 11.

git branch --show-current

: 현재 브랜치 이름 확인

 

git checkout 브랜치명

: 브랜치로 이동할 때

local에 브랜치가 없는 경우에는 아래와 같이 오류가 발생합니다.

그런 경우는 git fetch를 진행하여 다시 브랜치 이동하면됩니다.

 

 

git branch -r 
: 리모트 브랜치를 조회

git branch -a
: 로컬 저장소와 원격 저장소의 모든 브랜치를 조회

 

branch reference update

git fetch -p 와 git fetch --prune 동일
:로컬 저장소를 최신 정보로 갱신(리모트 저장소와 동기화)하며 자동적으로 더이상 유효하지 않은 참조를 제거합니다.
(즉, 원격(origin)에서는 이미 지워진 브랜치인데, 로컬에는 아직 남아있는 "가짜 브랜치들"을 없애줍니다.)  
: 팀원이 원격 브랜치를 삭제했는데, 내 로컬에는 아직 목록에 보일 때 정리할 때 사용하면 좋습니다 ㅎ
-p는 --prune의 짧은(short) 옵션입니다.

 

 

git fetch --all
: origin뿐 아니라 여러 remote에서 브랜치를 모두 최신 상태로 업데이트 가능합니다.(단, 브랜치를 지우진 않고, 최신 정보를 갖고옴)

 


git fetch --all -p
→ 모든 원격 브랜치를 최신으로 가져옵니다
→ 동시에 더 이상 존재하지 않는 브랜치도 정리해주는 깔끔한 fetch 명령어!

 

 

 

 

참고 url : 
https://stackoverflow.com/questions/16408300/what-are-the-differences-between-local-branch-local-tracking-branch-remote-bra/24785777
https://stackoverflow.com/questions/17712468/what-is-the-difference-between-git-remote-update-git-fetch-and-git-pull
https://stackoverflow.com/questions/41406903/remote-git-branches-not-visible/41407485#41407485

반응형

댓글