← 전체 글로 돌아가기

Git

Git remote가 여러 개일 때 push 대상 확인하기

fork한 저장소와 원본 저장소에 모두 push 권한이 있으면 헷갈릴 수 있다. git remote -v로 현재 설정을 항상 확인하자.

Git remote가 두 개 이상 있으면 push할 때 "어라, 이게 어디로 가는 거지?" 하는 불안감이 생긴다.

현재 remote 확인하는 방법

git remote -v
# origin과 upstream을 구분해서 보기

git config --get remote.origin.url
# 현재 origin의 실제 URL 확인

fork한 저장소라면 이렇게 설정하자

git remote add upstream https://github.com/original/repo.git
# 원본 저장소를 upstream으로 추가

git remote add origin https://github.com/myaccount/repo.git
# 내 fork를 origin으로 설정

이렇게 하면 git push origin = 내 저장소, git push upstream = 원본이 된다.

대응 절차

  1. 현재 remote 설정 확인: git remote -v
  2. 현재 브랜치 확인: git branch
  3. origin인지 upstream인지 명시하고 push: git push origin main 또는 git push upstream main

특히 원본 저장소에 실수로 push하는 것만 막으면 대부분의 문제는 없다.