[GitHub 100일 챌린지] Day 31 - Remote Repository 이해
[GitHub 100일 챌린지] Day 31 - Remote Repository 이해
100일 챌린지 Day 31 - Remote Repository와 로컬의 관계를 이해합니다
배울 내용
- Remote Repository 개념과 역할
- Origin과 Upstream의 차이
- Remote 연결 설정과 관리
Topic1. Remote Repository란?
Remote = 원격 저장소
GitHub에 있는 저장소를 말합니다.
로컬 vs 리모트
로컬 저장소 (Local Repository):
1
2
내 컴퓨터에 있는 Git 저장소
~/projects/my-app/.git
원격 저장소 (Remote Repository):
1
2
GitHub 서버에 있는 저장소
https://github.com/username/my-app
왜 Remote가 필요한가?
1. 백업:
1
2
로컬 컴퓨터 고장 → 데이터 손실
Remote 있음 → 안전하게 복구
2. 협업:
1
2
혼자: 로컬만 있어도 됨
팀: Remote로 코드 공유 필수
3. 여러 기기:
1
2
회사 컴퓨터 ←→ Remote ←→ 집 컴퓨터
동기화 가능
4. 포트폴리오:
1
2
GitHub 프로필 → 내 코드 공개
취업/이직 시 증명 자료
해보기: Remote 확인하기
1
2
3
4
5
6
7
8
9
# 1. 기존 프로젝트로 이동
cd ~/projects/my-app
# 2. Remote 확인
git remote -v
# 출력 예시:
# origin https://github.com/username/my-app.git (fetch)
# origin https://github.com/username/my-app.git (push)
결과: Remote 저장소가 설정되어 있으면 origin이 표시됩니다
Topic2. Origin과 Upstream
Remote에는 이름이 있습니다. 가장 흔한 이름들을 알아봅시다.
Origin
Origin = 기본 원격 저장소
1
2
3
내가 Clone한 원본 저장소
또는
내가 만든 저장소
예시:
1
2
3
4
5
6
# GitHub에서 Clone
git clone https://github.com/myname/my-app.git
# 자동으로 origin 설정됨
git remote -v
# origin https://github.com/myname/my-app.git
Upstream
Upstream = 원본 프로젝트
Fork한 경우에 사용합니다.
1
2
3
4
5
Original Repository (Upstream)
↓ Fork
My Repository (Origin)
↓ Clone
Local Repository
시나리오:
1
2
3
4
5
6
7
8
9
10
11
1. 오픈소스 프로젝트 발견
https://github.com/facebook/react
2. 내 계정으로 Fork
https://github.com/myname/react
3. 내 컴퓨터로 Clone
git clone https://github.com/myname/react.git
4. Upstream 추가
git remote add upstream https://github.com/facebook/react.git
Remote 이름 규칙
일반적인 이름:
1
2
3
4
origin → 내 저장소 (가장 흔함)
upstream → 원본 저장소 (Fork 시)
deploy → 배포 저장소
backup → 백업용 저장소
커스텀 이름도 가능:
1
2
git remote add myserver https://...
git remote add company https://...
해보기: Remote 여러 개 설정
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 1. 현재 Remote 확인
git remote -v
# 2. 새 Remote 추가
git remote add backup https://github.com/myname/my-app-backup.git
# 3. 다시 확인
git remote -v
# origin https://github.com/myname/my-app.git (fetch)
# origin https://github.com/myname/my-app.git (push)
# backup https://github.com/myname/my-app-backup.git (fetch)
# backup https://github.com/myname/my-app-backup.git (push)
# 4. Remote 제거 (연습용)
git remote remove backup
결과: Remote는 여러 개 설정할 수 있고, 이름을 자유롭게 지정 가능합니다
Topic3. Remote 연결 설정
Remote를 추가, 변경, 삭제하는 방법입니다.
Remote 추가
문법:
1
git remote add <이름> <URL>
예시:
1
2
3
4
5
# HTTPS 방식
git remote add origin https://github.com/username/repo.git
# SSH 방식
git remote add origin git@github.com:username/repo.git
Remote URL 확인
간단히 보기:
1
git remote -v
자세히 보기:
1
git remote show origin
출력 예시:
1
2
3
4
5
6
7
8
9
10
11
* remote origin
Fetch URL: https://github.com/username/repo.git
Push URL: https://github.com/username/repo.git
HEAD branch: main
Remote branches:
main tracked
dev tracked
Local branch configured for 'git pull':
main merges with remote main
Local ref configured for 'git push':
main pushes to main (up to date)
Remote URL 변경
HTTPS → SSH 변경:
1
2
3
4
5
6
7
8
9
10
# 1. 현재 URL 확인
git remote -v
# origin https://github.com/username/repo.git
# 2. URL 변경
git remote set-url origin git@github.com:username/repo.git
# 3. 확인
git remote -v
# origin git@github.com:username/repo.git
저장소 이동 시:
1
2
# 저장소를 다른 곳으로 이동했을 때
git remote set-url origin https://github.com/newname/repo.git
Remote 이름 변경
1
2
3
4
5
# origin → upstream으로 변경
git remote rename origin upstream
# 확인
git remote -v
Remote 삭제
1
2
3
4
5
# Remote 제거
git remote remove origin
# 또는
git remote rm origin
Remote 연결 테스트
1
2
# Remote에 연결 가능한지 테스트
git ls-remote origin
성공 시 출력:
1
2
3
abc123... HEAD
abc123... refs/heads/main
def456... refs/heads/dev
실패 시:
1
fatal: could not read from remote repository
해보기: Remote 설정 종합 실습
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 1. 새 프로젝트 만들기
mkdir test-remote
cd test-remote
git init
# 2. Remote 추가 (실제 저장소 필요)
git remote add origin https://github.com/username/test-repo.git
# 3. Remote 확인
git remote -v
# 4. Remote 상세 정보
git remote show origin
# 5. Remote 이름 변경
git remote rename origin myremote
# 6. 다시 원래대로
git remote rename myremote origin
# 7. Remote 제거
git remote remove origin
# 8. 확인
git remote -v
# (아무것도 안 나옴)
결과: Remote는 자유롭게 추가/변경/삭제할 수 있습니다
정리
완료 체크:
- Remote Repository의 개념과 역할을 이해한다
- Origin과 Upstream의 차이를 안다
- Remote를 추가, 변경, 삭제할 수 있다
핵심 명령어:
1
2
3
4
5
6
git remote -v # Remote 목록 보기
git remote add origin <URL> # Remote 추가
git remote show origin # Remote 상세 정보
git remote set-url origin <URL> # URL 변경
git remote rename old new # 이름 변경
git remote remove origin # Remote 삭제
Remote 흐름:
1
2
3
Local Repository ←→ Remote Repository (GitHub)
| |
내 컴퓨터 클라우드 서버
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.
