C.W.K.
Stream
Lesson 01 of 05 · published

Branch는 pointer야

~18 min · branch, pointers

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

branch 는 41 byte 파일

이 quest 전체에서 가장 중요한 문장: Git 의 branch 는 commit 을 가리키는 movable pointer 야. 복사본 아니야. 폴더 아니야. snapshot 아니야. hash 하나에 newline 붙은 41 byte 파일. branch 만들기 = 파일 한 번 쓰기. 이 한 줄이 Git 이 모든 일에 branching 을 권장하는 이유 (기능 작업, 실험, 일회용 디버깅, 코드 리뷰) 와 SVN 출신 팀들이 속도에 놀라는 이유야.

.git/refs/heads/ 들어가면 직접 보여. 파일 이름이 branch 이름, 파일 내용이 그 branch 가 현재 가리키는 commit hash. main, feature/login, chore/cleanup — 한 디렉토리의 형제들. 'main 이 특별하다' 는 마법 없어. 관습이 main 을 통합 branch 로 지정하고 도구가 강제할 뿐, 데이터 모양은 똑같아.

pointer 가 가리키는 게 그 branch 의 tip 이야. tip 에서 parent pointer 따라 거꾸로 걸으면 branch history 가 나와. old commit 을 공유하는 두 branch 는 거꾸로 걸으면 둘 다 공유 commit 에 도달해. 이게 Git 이 'feature 에 있고 main 에 없는 것' 을 계산하는 방법 — 도달 가능한 commit 의 set difference, 복사 없이.

함의가 멀리 가. branch 이름 바꾸기 = 파일 이름 바꾸기. branch 삭제 = 파일 제거 (commit 은 남아 orphaned, GC 가 정리). branch switch = HEAD 가 다른 ref 가리키게 하고 working tree 를 새 tip 에 맞춤. branch 를 pointer 로 보기 시작하면 나머지 branching 이 마법 같지 않고 file 연산 같아져.

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

scratch repo 에서 ls .git/refs/heads/cat .git/refs/heads/main 실행. git branch 로 branch 세 개 만들고, 각자 파일이 됐는지 확인. branch 하나를 손으로 다른 commit 으로 이동: git update-ref refs/heads/<name> <other-hash>. git log 로 branch 가 정말 거기 가리키는지 확인. file-level view 에서 의외였던 거 적어.

Progress

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

댓글 0

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

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