git remote
한 줄 요약
원격 저장소 연결을 관리 (추가, 삭제, 조회)
선행 지식
- Remote란 - 원격 저장소 개념
기본 사용법
# Remote 목록 보기
git remote
# Remote 추가
git remote add <이름> <URL>
# Remote 삭제
git remote remove <이름>주요 옵션
| 명령어 | 설명 | 예시 |
|---|---|---|
git remote | Remote 이름 목록 | git remote |
git remote -v | URL 포함 상세 목록 | git remote -v |
git remote add | Remote 추가 | git remote add origin URL |
git remote remove | Remote 삭제 | git remote remove origin |
git remote rename | Remote 이름 변경 | git remote rename old new |
git remote set-url | URL 변경 | git remote set-url origin URL |
git remote show | Remote 상세 정보 | git remote show origin |
실제 예제
Remote 목록 확인
$ git remote
origin
$ git remote -v
origin https://github.com/user/repo.git (fetch)
origin https://github.com/user/repo.git (push)Remote 추가
새로 만든 로컬 저장소를 GitHub에 연결:
# 1. GitHub에서 빈 저장소 생성
# 2. 로컬에서 Remote 추가
git remote add origin https://github.com/username/repo.git
# 3. 확인
git remote -v
origin https://github.com/username/repo.git (fetch)
origin https://github.com/username/repo.git (push)
# 4. 첫 push
git push -u origin main포크한 저장소에 upstream 추가
# 원본 저장소를 upstream으로 추가
git remote add upstream https://github.com/original/repo.git
# 확인
$ git remote -v
origin https://github.com/me/repo.git (fetch)
origin https://github.com/me/repo.git (push)
upstream https://github.com/original/repo.git (fetch)
upstream https://github.com/original/repo.git (push)
# 원본 저장소의 변경사항 가져오기
git fetch upstream
git merge upstream/mainRemote URL 변경
HTTPS에서 SSH로 변경하거나, 저장소 이름이 바뀌었을 때:
# 현재 URL 확인
git remote -v
# URL 변경
git remote set-url origin git@github.com:username/repo.git
# 확인
git remote -vRemote 상세 정보
$ git remote show origin
* remote origin
Fetch URL: https://github.com/user/repo.git
Push URL: https://github.com/user/repo.git
HEAD branch: main
Remote branches:
develop tracked
main tracked
Local branches configured for 'git pull':
main merges with remote main
Local refs configured for 'git push':
main pushes to main (up to date)Remote 삭제
git remote remove upstream
# 또는
git remote rm upstreamRemote 이름 변경
git remote rename origin githubHTTPS vs SSH
| HTTPS | SSH |
|---|---|
https://github.com/user/repo.git | git@github.com:user/repo.git |
| 매번 인증 필요 (또는 credential 저장) | SSH 키로 인증 |
| 방화벽 친화적 | 포트 22 필요 |
| 설정 쉬움 | 초기 설정 필요 |
SSH 설정 방법
# 1. SSH 키 생성
ssh-keygen -t ed25519 -C "your_email@example.com"
# 2. 공개키 복사
cat ~/.ssh/id_ed25519.pub
# 3. GitHub에 공개키 등록
# Settings → SSH and GPG keys → New SSH key
# 4. 연결 테스트
ssh -T git@github.com자주 하는 실수
Remote가 이미 존재
$ git remote add origin https://...
error: remote origin already exists.해결:
# URL 변경
git remote set-url origin https://new-url.git
# 또는 삭제 후 다시 추가
git remote remove origin
git remote add origin https://new-url.gitpush 시 “No configured push destination”
$ git push
fatal: No configured push destination.해결:
git remote add origin https://github.com/user/repo.git
git push -u origin main잘못된 Remote URL
$ git push
fatal: repository 'https://...' not found확인 및 수정:
git remote -v
git remote set-url origin https://correct-url.git관련 명령어
- git clone - 원격 저장소 복제 (자동으로 origin 설정)
- git push - 원격에 업로드
- git pull과 fetch - 원격에서 다운로드
- git fetch - 원격 정보 업데이트
더 알아보기
- Remote란 - 원격 저장소 개념
- git push - 원격에 변경사항 올리기
- Pull Request란 - 원격 저장소 협업