yoongrammer

git remote 저장소 본문

VCS (Version Control System)/git

git remote 저장소

yoongrammer 2020. 11. 19. 22:21
728x90

목차

    git remote 저장소


    리모트 저장소(remote repository)는 인터넷이나 네트워크 어딘가에 있는 저장소를 말합니다.

    리모트 저장소에서 파일을 공유할 수 있기 때문에 여러 사람들과 협업이 가능합니다.

     

    로컬 저장소에서 리모트 저장소에 데이터를 업로드(push) 하거나 가져(pull) 올 수 있습니다.

     

    git remote 관련 명령어를 알아보도록 하겠습니다.

    리모트 저장소 확인하기 (git remote)


    git remote 명령으로 현재 프로젝트에 등록된 리모트 저장소를 확인할 수 있습니다.

    git clone으로 저장소를 clone 하면 origin이라는 리모트 저장소가 자동으로 등록됩니다.

    $ git clone https://github.com/schacon/ticgit
    Cloning into 'ticgit'...
    remote: Reusing existing pack: 1857, done.
    remote: Total 1857 (delta 0), reused 0 (delta 0)
    Receiving objects: 100% (1857/1857), 374.35 KiB | 268.00 KiB/s, done.
    Resolving deltas: 100% (772/772), done.
    Checking connectivity... done.
    
    $ cd ticgit
    
    $ git remote
    origin

    -v 옵션을 추가하여 단축이름과 URL을 함께 볼 수 있습니다.

    $ git remote -v
    origin	https://github.com/schacon/ticgit (fetch)
    origin	https://github.com/schacon/ticgit (push)

    리모트 저장소 추가하기 (git remote add)


    git remote add <단축이름> <url> 명령으로 리모트 저장소를 추가할 수 있습니다.

    $ git remote
    origin
    
    $ git remote add pb https://github.com/paulboone/ticgit
    
    $ git remote -v
    origin	https://github.com/schacon/ticgit (fetch)
    origin	https://github.com/schacon/ticgit (push)
    pb	https://github.com/paulboone/ticgit (fetch)
    pb	https://github.com/paulboone/ticgit (push)

    pb라는 remote 저장소가 추가된 것을 확인할 수 있습니다.

    리모트 저장소에서 데이터 가져오기 (git fetch, git pull)


    git fetch <remote> 명령으로 <remote> 저장소에서 데이터를 가져올 수 있습니다.

    <remote> 값이 없다면 clone 한 서버에서 데이터를 가져옵니다.

    $ git fetch

    fetch 명령은 로컬에 없는 데이터만 가져오고 자동으로 Merge 하지 않기 때문에 수동으로 Merge 해야 합니다.

    git pull <remote> 명령은 <remote> 저장소에서 데이터를 가져오고 그 데이터를 자동으로 Merge 하는 명령어입니다.

    <remote> 값이 없다면 clone 한 서버에서 데이터를 가져옵니다.

    git pullgit fetchgit merge 한 것과 같습니다.

    $ git pull

    리모트 저장소에 데이터 업로드하기 (git push)


    git push <리모트 저장소 이름> <브랜치 이름> 명령으로 데이터를 리모트 저장소에 업로드할 수 있습니다.

    master 브랜치를 origin 서버에 push 하려면 아래와 같이 사용하면 됩니다.

    $ git push origin master

    리모트 저장소 이름 바꾸기 (git remote rename)


    git remote rename <변경 전 브랜치 이름> <변경 후 브랜치 이름> 명령으로 리모트 저장소 이름을 변경할 수 있습니다.

    $ git remote rename pb paul
    $ git remote
    origin
    paul

    리모트 저장소 삭제하기 (git remote remove)


    git remote remove <remote> 명령으로 리모트 저장소를 삭제할 수 있습니다.

    $ git remote remove paul

     

    728x90
    Comments