Remote란
한 줄 요약
인터넷이나 네트워크에 있는 원격 저장소로, 협업과 백업에 사용
개요
Remote(원격 저장소)는 로컬 컴퓨터가 아닌 다른 곳에 있는 Git 저장소입니다. GitHub, GitLab, Bitbucket 등의 서비스에 호스팅되거나, 자체 서버에 구축할 수 있습니다.
핵심 포인트
- Remote는 협업과 백업의 핵심
- 하나의 로컬 저장소에 여러 Remote 연결 가능
- 가장 흔한 Remote 이름은
origin
시각적 이해
┌────────────────────────────────────────────────────────────────┐
│ Remote (GitHub) │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ origin/main: [c1]──▶[c2]──▶[c3]──▶[c4] │ │
│ └─────────────────────────────────────────────────────────┘ │
└────────────────────────────────────────────────────────────────┘
▲ │
│ push pull │
│ ▼
┌────────────────────────────────────────────────────────────────┐
│ Local (내 컴퓨터) │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ main: [c1]──▶[c2]──▶[c3]──▶[c4]──▶[c5] │ │
│ └─────────────────────────────────────────────────────────┘ │
└────────────────────────────────────────────────────────────────┘
Local vs Remote
| Local Repository | Remote Repository |
|---|---|
| 내 컴퓨터에 있음 | 서버/클라우드에 있음 |
| 오프라인 작업 가능 | 인터넷 필요 |
| 나만 접근 가능 | 팀원과 공유 가능 |
git commit으로 저장 | git push로 업로드 |
Remote가 필요한 이유
1. 협업
┌─────────────┐
│ Remote │
│ (GitHub) │
└─────────────┘
↗ ↑ ↖
push ↙ pull ↘ push
↗ ↓ ↖
┌─────┐ ┌─────┐ ┌─────┐
│개발자A│ │개발자B│ │개발자C│
└─────┘ └─────┘ └─────┘
2. 백업
로컬 컴퓨터가 망가져도 Remote에서 복구 가능
3. 배포
서버에서 Remote를 pull하여 최신 코드 배포
Remote 관련 명령어
| 명령어 | 설명 | 참고 |
|---|---|---|
git remote | Remote 목록/관리 | git remote |
git clone | Remote 복제 | git clone |
git push | Remote에 업로드 | git push |
git pull | Remote에서 다운로드 + 병합 | git pull과 fetch |
git fetch | Remote에서 다운로드만 | git pull과 fetch |
Remote 이름 규칙
origin
origin은 기본 Remote 이름입니다.
# clone할 때 자동으로 origin 설정
git clone https://github.com/user/repo.git
# origin = https://github.com/user/repo.git여러 Remote 사용
# origin: 내 저장소
git remote add origin https://github.com/me/repo.git
# upstream: 원본 저장소 (포크한 경우)
git remote add upstream https://github.com/original/repo.git원격 브랜치
Remote의 브랜치는 origin/main 형태로 표시됩니다:
$ git branch -a
* main # 로컬 브랜치
remotes/origin/main # 원격 브랜치
remotes/origin/develop원격 브랜치는 읽기 전용 스냅샷입니다:
git fetch로 업데이트- 직접 수정 불가, 로컬 브랜치로 체크아웃해서 작업
GitHub, GitLab, Bitbucket
| 서비스 | 특징 |
|---|---|
| GitHub | 가장 인기, 오픈소스 친화적 |
| GitLab | CI/CD 내장, 자체 호스팅 가능 |
| Bitbucket | Atlassian 도구와 연동 |
모두 Git Remote로 사용 가능합니다.
기본 워크플로우
# 1. Remote에서 복제
git clone https://github.com/user/repo.git
# 2. 로컬에서 작업
git add .
git commit -m "feat: 새 기능"
# 3. Remote에 업로드
git push origin main
# 4. 다른 사람의 변경사항 가져오기
git pull origin main자주 하는 실수
Remote가 없는 저장소에서 push
$ git push
fatal: No configured push destination.해결: Remote 추가
git remote add origin https://github.com/user/repo.git
git push -u origin mainorigin/main과 main 혼동
main: 로컬 브랜치origin/main: 원격 브랜치의 로컬 참조
관련 명령어
- git remote - Remote 관리
- git clone - 저장소 복제
- git push - 업로드
- git pull과 fetch - 다운로드
더 알아보기
- Repository - 저장소 개념
- Pull Request란 - Remote를 통한 협업
- git branch - 원격 브랜치 관리