본문 바로가기
C.W.K.
Stream
Lesson 01 of 05 · published

Branch는 pointer야

~18 min · branch, pointers

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

branch는 41 byte 파일이야

이 quest에서 가장 중요한 문장을 하나만 고르면 이거야. Git branch는 commit을 가리키며 움직이는 pointer야. 프로젝트 복사본도, 폴더도, snapshot도 아니고 hash 하나와 newline을 담은 41 byte 파일이지. branch를 만든다는 건 파일을 한 번 쓰는 일이야. 그래서 Git은 기능 작업, 실험, 잠깐의 debugging, code review까지 어디서나 branch를 쓰라고 권할 수 있어. SVN에 익숙한 팀이 그 속도에 놀라는 이유도 같아.

.git/refs/heads/를 열면 직접 확인할 수 있어. 파일 이름이 branch 이름이고, 파일 내용은 그 branch가 현재 가리키는 commit hash야. main, feature/login, chore/cleanup은 같은 directory의 형제일 뿐이야. main에 특별한 마법은 없어. 관습이 통합 branch로 삼고 도구가 그 규칙을 강제할 뿐, 데이터 모양은 모두 같아.

pointer가 가리키는 commit을 branch의 tip이라고 해. tip에서 parent pointer를 따라 과거로 걸으면 그 branch의 이력이 나와. 옛 commit을 공유하는 두 branch는 뒤로 가다 같은 commit에 닿지. Git은 이 도달 가능한 commit의 집합 차이로 'feature에는 있고 main에는 없는 것'을 계산해. 복사본은 필요 없어.

이 관점은 멀리까지 이어져. branch 이름 바꾸기는 파일 이름을 바꾸는 일이고, branch 삭제는 파일을 없애는 일이야. commit은 orphaned 상태로 남았다가 GC가 정리해. branch switchHEAD가 다른 ref를 가리키게 하고 작업 트리를 새 tip에 맞추는 일이야. branch를 pointer로 보면 나머지 branching도 마법이 아니라 파일 연산처럼 읽혀.

Code

Branch는 파일이야. 직접 확인해봐·bash
ls .git/refs/heads/
# main
# feature/login
# chore/cleanup

cat .git/refs/heads/main
# a1b2c3d4e5f6...    (commit hash + newline = 41 byte)

# packed ref 까지 같이 보는 plumbing 등가물:
git for-each-ref --format='%(refname:short) -> %(objectname:short)'
create / rename / delete — 다 pointer 연산·bash
# HEAD 에서 branch 만들기 (switch 안 함)
git branch feature/profile

# 특정 commit 에서:
git branch feature/profile abc1234

# 현재 branch 이름 바꾸기:
git branch -m new-name

# 삭제 (upstream 에 merge 됐을 때만):
git branch -d feature/profile

# 강제 삭제 (commit 이 orphan 됨):
git branch -D feature/profile

External links

Exercise

연습용 repo에서 ls .git/refs/heads/cat .git/refs/heads/main을 실행해. git branch로 branch 세 개를 만들고 각각 파일이 생겼는지 확인해. 이어서 git update-ref refs/heads/<name> <other-hash>로 branch 하나를 다른 commit으로 직접 옮겨. git log에서 정말 그곳을 가리키는지 확인하고 파일 수준의 모습에서 뜻밖이었던 점을 적어봐.

Progress

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

댓글 0

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

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