MyAI(마이아이)개발 · 제품 · 운영 학습 노트

Remote, Fetch, Pull, Push, Upstream

origin은 무엇인가

origin은 Remote Repository에 붙인 이름일 뿐이다.

origin → https://github.com/.../project.git

Remote 이름은 여러 개 둘 수 있다.

git remote add backup ...
git remote add upstream ...
git remote -v

Fetch

Fetch의 본질:

Remote의 최신 Git Object와 Ref 정보를 Local Repository로 가져온다.

flowchart LR
    R[GitHub<br/>stable → D] -->|git fetch origin| L[Local Repository<br/>origin/stable → D]
    L --> B[local stable은 아직 C일 수 있음]

즉:

fetch
= object 다운로드
+ remote-tracking refs 생성/갱신

하지만 Local Branch는 자동으로 움직이지 않는다.

Remote-Tracking Reference

stable
= Local Branch

origin/stable
= 마지막 fetch 시점에 Local이 알고 있는 origin의 stable 위치

Pull

Pull은 개념적으로:

fetch
+
현재 Branch에 통합

통합 방식은 설정에 따라 merge 또는 rebase가 될 수 있다.

stable 같은 기준 Branch는 불필요한 merge commit을 피하기 위해:

git pull --ff-only

처럼 Fast-forward only 정책을 둘 수 있다.

Push

Push는 Local Commit/Ref를 Remote로 보낸다.

첫 Push:

git push -u origin feature/camera

-u는 이후 Local Branch가 어떤 Remote Branch를 추적할지 upstream 관계를 설정한다.

Upstream의 두 의미

Remote 이름으로서 upstream

Fork Workflow에서 흔하다.

origin   → 내 Fork
upstream → 공식 원본

Branch upstream

Local Branch가 추적하는 대상이다.

local feature/camera
      ↓ tracks
origin/feature/camera

두 의미를 혼동하지 않는다.

Downstream

Downstream은 Git의 핵심 설정 이름이라기보다 관계 설명에 가깝다.

공식 원본 → Fork → Feature Branch
upstream           downstream

다른 사람이 Push한 Branch를 공동 작업

git fetch origin
git switch --track origin/feature/camera

가능하다.

하지만 둘이 같은 Branch를 동시에 Push하면 non-fast-forward 충돌이 자주 생긴다.

일반적으로는 각자 Branch를 분리하고 PR로 통합하는 편이 관리가 쉽다.