Git 09 - Remote repository

민정윤·2024년 10월 17일
0

Remote repository

복습
• GitHub 에서 Remote 저장소를 생성
• Git Clone 하여 사용할 수 있음.
• Local Repository 에서 Push, Pull (Fetch) 하여 동기화 할 수 있음.

Push : 내 작업을 공유할 때
Pull : 다른 사람의 작업을 가져올 때

local & remote 연결

git remote add <remote_repo_name> <remote_repo_url>
git remote add origin <remote_repo_url>
  • remote add : 동기화할 remote 레파지토리를 연결 및 관리할 수 있음
  • url : 여러 레파지토리를 등록 및 관리 가능 (잘 사용 안 함)
    • 그리고 default로 가장 중요한 레파지토리를 등록할 때는 반드시 'origin'으로 등록하기
    • 수동 git clone을 하면 자동으로 등록이 되는데 이때도 origin으로 등록이 됨

remote 저장소 주소 수정

계정 정보, 토큰을 넣지 않아서 매번 인증하기 귀찮을 때

git remote set-url <remote_repo_name> <remote_repo_new_url>
git remote set-url origin <remote_repo_new_url>
  • set-url : 뒤에 있는 url의 이름을 origin (저장소 이름)으로 바꾸겠다

remote 저장소 이름 수정

git remote rename <old_name> <new_name>

origin 같은 저장소 이름 수정


remote 저장소 삭제

git remote remove <remote_repo_name>
git remote remove origin

remote 저장소 정보 확인

  • 등록된 이름이랑 url 정보 확인하기
git remote -v

토큰 정보를 url에 포함해서 저장한 경우 누구다 열람할 수 있어서
공용 pc 에서는 토큰 정보 등록 X


remote 저장소 상세 정보 확인

  • show로 확인 가능
git remote show <remote_repo_name>
git remote show origin

연동 - pull

git pull <remote_repo_name> <branch_name>
git pull origin main

• Remote Repository 의 작업 내용을 Local Repository 에 동기화

• Fetch (download) 와 Merge 의 과정과 비슷

= pull 하면 remote에서 변경된 스냅샷을 local로 가져오는 것

  • Fetch (download) 해서 내 작업과 merge 병합해주는 것.
  • 만약에 main branch에서 git pull만 했을 때 디폴트로 remote에 있는 main과 연결이 됨.
  • 다른 branch에서 pull을 하면 remote에 다른 branch를 가져와서 동기화 해줌.

연동 - push

git push <remote_repo_name> <branch_name>
git push origin main

• Local Repository 에서 작업한 내용을 Remote Repository 에 배포할 때

0개의 댓글