포스트

[GitHub 100일 챌린지] Day 52 - Upstream과 Origin 원격 저장소

[GitHub 100일 챌린지] Day 52 - Upstream과 Origin 원격 저장소

100일 챌린지 Day 52 - Fork한 저장소에서는 Upstream(원본)과 Origin(내 Fork) 두 개의 원격 저장소를 관리합니다.

배울 내용

  1. Upstream과 Origin의 정확한 의미와 차이
  2. 원격 저장소 추가, 확인, 제거 방법
  3. 각 원격 저장소에서 코드 가져오기와 푸시하기

1. Upstream과 Origin 이해하기

원격 저장소 구조

graph TB
    U[facebook/react<br/>📦 Upstream] -.->|Fork| O[myname/react<br/>🍴 Origin]
    O -->|git clone| L[로컬 저장소<br/>💻 Local]
    L -->|git push| O
    L -.->|git fetch/pull| U
    O -.->|Pull Request| U

용어 정의

용어 의미 역할
Upstream 원본 저장소 Fork 출처, 최신 변경사항 동기화
Origin 내 Fork 저장소 내 작업 저장, PR 출발점
Local 내 컴퓨터 실제 코드 작업 공간
1
2
3
4
5
6
7
8
# 원격 저장소 확인
git remote -v

# 출력:
# origin    https://github.com/myname/react.git (fetch)
# origin    https://github.com/myname/react.git (push)
# upstream  https://github.com/facebook/react.git (fetch)
# upstream  https://github.com/facebook/react.git (push)

2. Origin - 내 Fork 저장소

Origin 자동 설정

1
2
3
4
5
6
7
# Fork한 저장소 Clone
git clone https://github.com/myname/react.git
cd react

# origin 자동 설정됨
git remote -v
# origin  https://github.com/myname/react.git

Origin에 Push하기

1
2
3
4
git checkout -b feature-new-hook
git add .
git commit -m "feat: Add useCustomHook"
git push origin feature-new-hook

3. Upstream 추가하기

Upstream 설정

1
2
3
4
5
# Upstream 추가
git remote add upstream https://github.com/facebook/react.git

# 확인
git remote -v

Upstream에서 가져오기

1
2
3
4
5
# 최신 변경사항 가져오기
git fetch upstream
git checkout main
git merge upstream/main
git push origin main

4. 원격 저장소 관리 명령어

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 조회
git remote              # 이름만
git remote -v           # URL 포함
git remote show origin  # 상세 정보

# 추가
git remote add upstream https://github.com/original/project.git

# URL 변경
git remote set-url origin git@github.com:myname/project.git

# 이름 변경
git remote rename origin myfork

# 제거
git remote remove upstream

5. Fetch vs Pull

Fetch (안전)

1
2
3
git fetch upstream       # 가져오기만
git log upstream/main   # 확인
git merge upstream/main # 검토 후 병합

Pull (빠름)

1
git pull upstream main  # 가져오기 + 병합

정리

완료 체크:

  • Upstream과 Origin의 차이를 설명할 수 있다
  • 원격 저장소를 추가하고 확인할 수 있다
  • Upstream에서 최신 변경사항을 가져올 수 있다

핵심 요약:

  • Origin = 내 Fork (자유롭게 Push)
  • Upstream = 원본 (Fetch만 가능)
  • git remote add upstream <URL>
  • git fetch upstream → 변경사항 가져오기

다음: Day 53 - Upstream 동기화


이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.