Today
-
Yesterday
-
Total
-
  • Github에서 분기(fork)한 저장소를 Magit으로 원본과 동기화하기
    Programmer/Emacs 2019. 2. 19. 10:07

    이 문서는 원본 저장소에 푸시 권한이 없는 개발자가 분기(fork)이후 원본과 동기화하는 방법을 설명한다.
    도구는 이맥스의 git 확장 모듈인 magit을 사용한다.
    커맨드라인 git을 활용한 문서는 많다.
    이런 저런 문서를 참고하라.


    이 글은 magit을 활용하여 이를 해보려고 한다.

    Head:     master Make perfect
    Merge:    origin/master Make perfect
    
    Recent commits
    
    -UUU:%%--F1  magit: tiny-tool   Top L4     (Magit) ---------------------
     
    


    'y'을 누러 원격 저장소를 확인해보자.

    Branches (2)
      develop                         origin/develop Do something
      master                          origin/master Make perfect
    
    Remote origin (https://github.com/YOUR_USERNAME/tiny-tool.git) (2)
      develop                         Make perfect
      master                          Make perfect


    'M', 'a'를 눌러 원본 저장소를 추가한다.[각주:1]
    미니버퍼의 물음(기울임체)에 오른쪽의 내용을 입력한다.
    Remote name: upstream
    Remote url: https://github.com/ORIGINAL_OWNER/tiny-tool.git
    Set `remote.pushDefault' to "upstream"? (y or n)[각주:2] : n[각주:3]

    Configure origin
     u remote.origin.url     https://github.com/YOUR_USERNAME/tiny-tool.git
     U remote.origin.fetch   +refs/heads/*:refs/remotes/origin/*
     s remote.origin.pushurl unset
     S remote.origin.push    unset
     O remote.origin.tagOpts [--no-tags|--tags]
    
    Switches for add
     -f Fetch after add (-f)
    
    Actions
     a Add                     C Configure...
     r Rename                  p Prune stale branches
     k Remove                  P Prune stale refspecs
    
    -UUU:%%--F1  magit: tiny-tool   Top L4     (Magit) ---------------------
    Remote name: upstream
    
    -UUU:%%--F1  magit: tiny-tool   Top L4     (Magit) ---------------------
    Remote name: https://github.com/ORIGINAL_OWNER/tiny-tool.git
    
    -UUU:%%--F1  magit: tiny-tool   Top L4     (Magit) ---------------------
    Set `remote.pushDefault' to "upstream"? (y or n) n
    

    제대로 추가되었는지 'y'를 눌러 확인한다.

    Branches (2)
      develop                         origin/develop Do something
      master                          origin/master Make perfect
    
    Remote origin (https://github.com/YOUR_USERNAME/tiny-tool.git) (2)
      develop                         Make perfect
      master                          Make perfect
    
    Remote upstream (https://github.com/ORIGINAL_OWNER/tiny-tool.git) (2)
      develop                         Do something else
      master                          Make perfect


    이미 upstream을 추가했다면, 최신 상태로 업데이트가 필요하다.
    'f', 'e'를 누르고 미니버퍼에 'upstream'을 입력한다.

    Switches
     -p Prune deleted branches (--prune)
    
    Configure
     C variables...
    
    Fetch from
     u origin
     e elsewhere
     a all remotes
    
    Fetch
     o another branch
     r explicit refspec
     m submodules
    
    -UUU:%%--F1  magit: tiny-tool   Top L4     (Magit) ---------------------
    Fetch remote (default origin): upstream
    


    원본 저장소의 브랜치(branch)를 나의 브랜치에 병합(merge)한다.
    여기서는 편의상 'develop' 브랜치를 사용한다.

    우선, 'b', 'b'를 눌러 'develop' 브랜치로 이동한다.

    Configure master
     d branch.master.description unset
     u branch.master.merge       refs/heads/master
       branch.master.remote      origin
     r branch.master.rebase      [true|false|default:false]
     p branch.master.pushRemote  [origin|upstream]
    
    Configure repository defaults
     M-r pull.rebase        [true|false|default:false]
     M-p remote.pushDefault [origin|upstream]
    
    Configure branch creation
     U branch.autoSetupMerge  [always|true|false|default:true]
     R branch.autoSetupRebase [always|local|remote|never|default:never]
    
    Actions
     b Checkout                    
     C Configure...                l Checkout local branch
     s Create new spin-off         m Rename
     c Checkout new branch         n Create new branch
     x Reset                       w Checkout new worktree
     W Create new worktree         k Delete
     y Checkout pull-request       Y Create from pull-request
    
    -UUU:%%--F1  magit: tiny-tool   Top L4     (Magit) ---------------------
    Checkout: develop


    'm', 'm'을 누르고 'upstream/develop'을 입력하여 원본 저장소의 브랜치를 나의 브랜치에 병합한다.[각주:4]

    Switches
     -f Fast-forward only (--ff-only)
     -n No fast-forward (--no-ff)
    
    Options
     =s Strategy (--strategy=)
    
    Actions
     m Merge                     p Preview merge
     e Merge and edit message    
     n Merge but don't commit    s Squash merge
     a Absorb                    i Merge into
    
    -UUU:%%--F1  magit: tiny-tool   Top L4     (Magit) ---------------------
    Merge: upstream/develop


    마지막으로 'P', 'u'를 눌러 변경한 내용을 내 저장소에 푸시(push)한다.

    Switches
     -f Force with lease (--force-with-lease)
     -F Force (--force)
     -h Disable hooks (--no-verify)
     -d Dry run (--dry-run)
    
    Configure
     C variables...
    
    Push master to
     p pushRemote, after setting that
     u origin/master
     e elsewhere
    
    Push
     o another branch       T a tag
     r explicit refspecs    t all tags
     m matching branches


    1. '-f' 옵션이 기본값으로 저상소를 추가한 뒤에 최신 업데이트를 가져온다.
      즉, 가져오기(fetch) 명령을 실행할 필요가 없다.
      이미 원본이 추가되었다면 가져오기와 병합을 해줘야 한다. [본문으로]
    2. (defalias 'yes-or-no-p 'y-or-n-p) 때문에 '(y or n)'로 물어본다. 이것이 없으면 '(yes or no)'를 요구한다. [본문으로]
    3. y/n 중에 무엇이 의도에 적합한지 모르겠다. [본문으로]
    4. 당연히 테스트를 해야한다. [본문으로]

    댓글

Designed by Tistory.