ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Git - Remote
    Git 2020. 5. 11. 19:48

    아래의 내용은 'Pro-Git'을 바탕으로 작성하였습니다.

    Remote Repository

    • git clone 시 자동으로 origin(remote repo) 등록됨

        # 단축이름 및 주소 출력
        $ git remote -v
        origin https://github.com/schacon/ticgit (fetch) 
        origin https://github.com/schacon/ticgit (push)
      
        # remote repo 등록
        $ git remote add [name] [url]
      
        # git fetch or pull
        $ git fetch [remote_name]
        $ git pull [remote_name]
      
        # git push 
        $ git push [remote_name] [branch_name]

    git fetch vs git pull

    • fetch: 원격 저장소의 모든 데이터를 가져온다
      • 로컬에 변경사항이 있을 경우 수동으로 변경하고 merge해야한다.
    • pull: 원격 저장소의 모든 데이터를 가져온다.
      • 로컬에 변경사항이 있을 경우 자동으로 merge

    git push

    • 만약, remote 저장소를 A와 내가 Clone → A가 push → 내가 push할 수 없음

      → 다른 사람(A)이 push한 내용을 pull(또는 fetch 후 merge) 이후 push 할 수 있다.

    원격 저장소 정보 확인

    # 등록된 원격 저장소 이름 출력
    git remote show
    # 해당 원격 저장소에 대한 상세 정보 출력
    git remote show [remote_name]

    원격 저장소 이름 변경 또는 삭제

    # 저장소 이름 변경
    $ git remote rename [before_name] [after_name]
    # 저장소 삭제
    $ git remote remove [remote_name]

    Tag

    # tag 확인
    git tag
    
    # lightweight tag 추가
    $ git tag v1.4-lw
    
    # annotated tag 추가
    $ git tag -a v1.4 -m "my version 1.4"
    
    # tag 및 커밋 정보 확인
    $ git show v1.4
    tag v1.4
    Tagger: jihoon <jihoon1493@gmail.com>
    Date:   Sat May 9 13:26:44 2020 +0000
    
    my version 1.4
    
    commit 6e6072736311d3bc85d1d871a0d646ea71a23cf2
    Author: jihoon <jihoon1493@gmail.com>
    Date:   Sat May 9 12:37:43 2020 +0000
    
        initial commit
    
    diff --git a/README.md b/README.md
    new file mode 100644
    index 0000000..e69de29
    diff --git a/forgotten_file b/forgotten_file
    new file mode 100644
    index 0000000..e69de29

    Tag - 기존 히스토리에 tag 추가

    # 한줄로 log 출력
    $ git log --pretty=oneline
    6e60727... initial commit
    9093b20... test6  # test6에 tag 추가
    14d5146... test5
    
    # annotated tag 생성(체크섬 일부로 생성할 수 있음)
    $ git tag -a v1.0 9093b20 -m 'my version 1.0'
    
    # tag 확인
    $ git show v1.0
    tag v1.0
    Tagger: jihoon <jihoon1493@gmail.com>
    Date:   Sat May 9 13:31:40 2020 +0000
    
    my version 1.0
    
    commit 9093b208fe279fc3a8c7bae6492c76dddf63855c
    Author: jihoon <jihoon1493@gmail.com>
    Date:   Fri May 8 15:25:25 2020 +0000
    
        test6
    
    diff --git a/README b/README
    deleted file mode 100644
    index e69de29..0000000

    Tag - Tag push

    • tag는 자동으로 push되지 않기 때문에 별도로 push 해야함

    • clone 또는 pull 시 tag도 포함됨

        # tag push
        $ git push origin [tag_name]
      
        # 모든 tag(remote에 push되지 않은) push
        $ git push origin --tags

    v0.1 tag가 push 되었을 때 - github

    Tag - Checkout

    • tag가 가리키는 특정 커밋을 기반으로 브랜치를 생성하여 작업을 진행할 때 사용

        # tag checkout
        git checkout -b [branch_name] [tag_name]
      
        # tag가 가리키는 커밋 시점의 브랜치 생성
        $ git checkout -b branch_v0.1 v0.1
        Switched to a new branch 'branch_v0.1'
        # branch 확인
        $ git branch
        * branch_v0.1
          master
        # log 확인 - 해당 커밋(first)의 브랜치가 생성되어 체크아웃(branch_v0.1) 되었으므로
        # 한 개의 로그가 출력된다.
        git log --pretty=oneline
        cb40f891c... first

    git Alias

    • git 명령어의 별칭을 만들어 사용할 수 있다.

        # 별칭 등록
        $ git config --global alias.co checkout 
        $ git config --global alias.br branch
        $ git config --global alias.ci commit
        $ git config --global alias.cim 'commit -m'
        $ git config --global alias.ciam 'commit -a -m'
        $ git config --global alias.st status
        $ git config --global alias.unstage 'reset HEAD --'
        $ git config --global alias.last 'log -1 HEAD'
        $ git config --global alias.graph 'log --oneline --decorate --graph --all'
      
        # 별칭 사용
        $ git co [branch_name]
        $ git br [branch_name]
        $ git ci -m 'test'
        $ git cim 'test' # 위와 동일
        # git commit -a -m 'message': git add [file] + git commit -m 'message'
        $ git ciam 'test'
        $ git st
        $ git unstage [file_name]
        $ git last  # 마지막 커밋 하나 출력
        $ git graph

    Issue & Pull Request

    GitHub로 프로젝트 관리하기 Part1 - 이슈 발급 부터 코드리뷰까지 | Popit

    Issue 작성

    # task
    - [ ] task1  # 체크 박스 생성
    - [ ] task2
    
    # issue 닫기
    # pull request에서 본문에 'resolved: #<number>' 사용 시
    # issue가 자동으로 닫힌다.
    

    task1을 체크할 경우

     

    참고

    https://git-scm.com/book/ko/v2

    GitHub로 프로젝트 관리하기 Part1 - 이슈 발급 부터 코드리뷰까지 | Popit

    'Git' 카테고리의 다른 글

    Git - Branch  (0) 2020.05.11
    Git - Local 기초  (0) 2020.05.11

    댓글

Designed by Tistory.