git remote

한 줄 요약

원격 저장소 연결을 관리 (추가, 삭제, 조회)

선행 지식

기본 사용법

# Remote 목록 보기
git remote
 
# Remote 추가
git remote add <> <URL>
 
# Remote 삭제
git remote remove <>

주요 옵션

명령어설명예시
git remoteRemote 이름 목록git remote
git remote -vURL 포함 상세 목록git remote -v
git remote addRemote 추가git remote add origin URL
git remote removeRemote 삭제git remote remove origin
git remote renameRemote 이름 변경git remote rename old new
git remote set-urlURL 변경git remote set-url origin URL
git remote showRemote 상세 정보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/main

Remote URL 변경

HTTPS에서 SSH로 변경하거나, 저장소 이름이 바뀌었을 때:

# 현재 URL 확인
git remote -v
 
# URL 변경
git remote set-url origin git@github.com:username/repo.git
 
# 확인
git remote -v

Remote 상세 정보

$ 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 upstream

Remote 이름 변경

git remote rename origin github

HTTPS vs SSH

HTTPSSSH
https://github.com/user/repo.gitgit@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.git

push 시 “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

관련 명령어

더 알아보기