VCS/Git

[Pro Git] 2-5. Git의 기초: 리모트 저장소

noahkim_ 2024. 1. 14. 19:53

Scott Chacon & Ben Straub 님의 "Pro Git" 책을 정리한 포스팅 입니다.

 

1. 리모트 저장소

리모트 저장소란?

  • 인터넷이나 네트워크 어딘가에 있는 저장소를 말합니다.

 

특징
  • 원격으로 다른사람과 협업 할 수 있습니다.
    • Pull, Push 명령어
  • 권한 부여
    • 저장소마다 읽고 쓰는 등의 권한을 줄 수 있습니다.

 

리모트 저장소 확인

git remote -v
  • 현재 프로젝트에 등록된 리모트 저장소를 확인할 수 있습니다.
  • git clone 명령어를 통해 복제하면, 'origin' 이라는 리모트 저장소가 자동으로 등록됩니다.

 

리모트 저장소 추가

git remote add <단축이름> <url>

 

 

리모트 저장소 fetch

git fetch <remote>
  • clone하거나 fetch한 이후, 수정된 모든 것을 로컬에 가져옵니다.
  • 단, 자동으로 working directory와 merge 하지 않습니다.

 

리모트 저장소 pull

git pull <remote>
  • clone하거나 fetch한 이후, 수정된 모든 것을 로컬에 가져옵니다.
  • 자동으로 working directory와 merge 합니다.

 

리모트 저장소 push

git push <remote> <branch>
  • working directory의 <branch>를 <remote>의 <branch>에 push 하는 것을 의미합니다.

 

리모트 저장소 살펴보기

git remote show <remote>
  • 리모트 저장소의 url과 추적하는 브랜치를 출력합니다.

 

$ git remote show origin
* remote origin
  URL: https://github.com/my-org/complex-project
  Fetch URL: https://github.com/my-org/complex-project
  Push  URL: https://github.com/my-org/complex-project
  HEAD branch: master
  Remote branches:
    master                           tracked
    dev-branch                       tracked
    markdown-strip                   tracked
    issue-43                         new (next fetch will store in remotes/origin)
    issue-45                         new (next fetch will store in remotes/origin)
    refs/remotes/origin/issue-11     stale (use 'git remote prune' to remove)
  Local branches configured for 'git pull':
    dev-branch merges with remote dev-branch
    master     merges with remote master
  Local refs configured for 'git push':
    dev-branch                     pushes to dev-branch                     (up to date)
    markdown-strip                 pushes to markdown-strip                 (up to date)
    master                         pushes to master                         (up to date)
remote branches
  • tracked : 로컬 저장소가 원격 브랜치의 존재를 인지하고 있음을 의미합니다.
  • new : 로컬에 존재하지 않지만 원격에는 새롭게 추가된 브랜치 입니다.
  • stale : 원격 저장소에서 삭제되었지만 로컬에는 여전히 남아있는 브랜치 입니다.
    • "git remote prune" 명령어를 통해 삭제 가능합니다.

 

기본 원격 브랜치 정보
  • 설정 명령어
git branch --set-upstream-to=<remote branch> <local branch>

 

 

리모트 저장소 이름 변경

git remote rename <old_name> <new_name>

 

리모트 저장소 삭제

git remote remove <remote>