Blog

GitHub에서 Fork 및 Pull Request (PR) 작성 방법을 알아보기 위해 저장소를 만들었습니다.
이 문서는 XpressEngine으로 Pull Request(PR) 작성 방법을 습득하기 위하여 작성되었습니다.
Linux에 Git이 설치되어 있으며 GitHub에 아이디가 생성되어 있어야 합니다.

주요 정보

akasima 아이디로 Pull-Request-test 저장소를 만들었습니다.
XpressEngine과 동일한 코드 수정 및 예시를 작성하기 위해 XpressEngine의 코드를 올려두었습니다.

용어 정리

  • PR : Pull Request. 이하 문서에서 Pull Request는 PR로 작성합니다.
  • 컨트리뷰터 : akasima-pr-sender와 같은 프로젝트 기여자 (이슈 작성자, PR 작성자)
  • local 저장소 : Linux에 설치된 git 저장소, akasima-pr-sender의 Linux
  • remote 저장소 : GitHub의 저장소
  • remote 원본 저장소 : akasima-pr-sender가 fork한 GitHub akasima의 저장소
  • remote 컨트리뷰터 저장소 : akasima-pr-sender가 fork한 저장소

이하 컨트리뷰터로 GitHub에 로그인했으며 Local 저장소 예시 또한 모두 컨트리뷰터의 저장소입니다.

Github에서 저장소 Fork 하기

akasima-pr-sender는 어떤 저장소도 갖고 있지 않습니다.

image1.png



GitHub의 akasima Pull-Request-Test 저장소로 이동해서 fork합니다.

image2.png



image3.png



저장소를 fork 중입니다. 완료되면 아래 페이지로 이동됩니다.

image4.png



fork가 완료되었습니다. fork 완료 후 컨트리뷰터의 저장소로 이동됩니다.

Fork 한 저장소를 컨트리뷰터의 local 저장소로 clone 하기

fork된 저장소를 컨트리뷰터의 Local 저장소로 clone 합니다.

image5.png



Local 저장소에 아래 명령어를 입력합니다. (복사한 내 remote 저장소 URL 입력)

[vagrant@localhost git-akasiman-pr-sender]$ git clone https://github.com/akasima-pr-sender/Pull-Request-Test.git
 Cloning into 'Pull-Request-Test'...
 remote: Counting objects: 3688, done.
 remote: Compressing objects: 100% (2594/2594), done.
 remote: Total 3688 (delta 867), reused 3688 (delta 867)
 Receiving objects: 100% (3688/3688), 7.45 MiB | 1.47 MiB/s, done.
 Resolving deltas: 100% (867/867), done.
[vagrant@localhost git-akasiman-pr-sender]$ ls
 Pull-Request-Test
 Pull-Request-Test

clone한 디렉토리로 이동 합니다.

[vagrant@localhost git-akasiman-pr-sender]$ cd Pull-Request-Test

PR 보내기 준비

XpressEngine 저장소는 develop branch로 PR 보내는 것을 원칙으로 합니다. master branch로 PR을 보내면 받지 않습니다.
Pull-Request-Test 저장소에서도 develop branch에 PR을 보내기 위한 연습을 하겠습니다.

local 저장소의 branch를 develop branch로 변경합니다.

[vagrant@localhost Pull-Request-Test]$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/develop
  remotes/origin/master
[vagrant@localhost Pull-Request-Test]$ git checkout develop
 Branch develop set up to track remote branch develop from origin.
 Switched to a new branch 'develop'
[vagrant@localhost Pull-Request-Test]$ git branch -a
* develop
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/develop
  remotes/origin/master

이제 PR을 보내기 위한 준비를 마쳤습니다.
파일을 임의로 수정하고 PR 작성하는 예시를 보겠습니다.

PR 보내기

local 저장소의 수정사하을 remote 컨트리뷰터 저장소로 보내기

develop branch에서 PR을 보내기 위한 수정을 처리하게 되면 PR 보낼 때 문제가 발생하게 됩니다.
발생할 문제에 대해서는 뒤에 언급 하도록 하겠습니다. develop branch로 PR을 보내므로 develop branch에서 새로운 branch를 생성합니다.

[vagrant@localhost member]$ git checkout -b develop-prtest1
 Switched to a new branch 'develop-prtest1'

develop-prtest1은 임의로 정한 branch 이름입니다. 개인의 취향에 맞게 작성하시면 됩니다.

Pull-Request-Test/modules/member/member.view.php를 수정하고 commit 합니다. (수정내용은 중요하지 않습니다. PR작성을 어떻게 하는지 확인하기 위한 문서이므로 수정 내용에 대한 언급은 않겠습니다.)

[vagrant@localhost Pull-Request-Test]$ vi modules/member/member.view.php
[vagrant@localhost Pull-Request-Test]$ git add modules/member/member.view.php
[vagrant@localhost Pull-Request-Test]$ git commit -m "member view 수정"
[develop-prtest1 af7c490] member view 수정
 1 file changed, 2 insertions(+)

수정 변경 사항을 내 저장소로 push 합니다.

[vagrant@localhost Pull-Request-Test]$ git push origin develop-prtest1
 Username for 'https://github.com': akasima-pr-sender(GitHub ID)
 Password for 'https://akasima-pr-sender@github.com': (GitHub PassWord)
 Counting objects: 9, done.
 Delta compression using up to 2 threads.
 Compressing objects: 100% (5/5), done.
 Writing objects: 100% (5/5), 446 bytes | 0 bytes/s, done.
 Total 5 (delta 4), reused 0 (delta 0)
 To https://github.com/akasima-pr-sender/Pull-Request-Test.git
 * [new branch]      develop-prtest1 -> develop-prtest1

컨트리뷰터의 remote 저장소에 develop-prtest1 branch가 생성되고 commit 내용이 push 되었습니다.

image6.png



remote 컨트리뷰터 저장소의 수정 내용을 remote 원본 저장소로 보내기 (Pull Request)

이제 remote 원본 저장소로 PR을 보냅니다.
컨트리뷰터의 remote 저장소인 GitHub 페이지로 이동합니다.
GitHub에서 PR보낼 commit이 있는 branch로 이동합니다.

image7.png



이동 페이지에서 compare & pull request를 클릭합니다.

image8.png



보내는 저장소와 받는 저장소를 확인합니다.

image9.png



akasima-pr-sender 저장소의 develop-prtest1 branch 의 수정된 내용을 akasima저장소의 develp branch로 보내야 합니다. 현재 akasima 저장소의 master branch로 보내도록 되어 있으므로 branch를 develop으로 변경합니다.

image10.png



image11.png



PR보낼 제목 및 내용을 작성하고 하단에 수정 내용및 PR에 포함된 commit을 확인합니다. PR 보낼 commit이 맞는지 수정된 내용이 정상적으로 포함 되었는지 확인합니다.

image12.png



Create Pull Request를 클릭하여 PR을 보냅니다.

image13.png



처리 후 akasima의 Pull-Request-Test 저장소로 이동됩니다.

image14.png



작성 후 branch 및 보낸 수정사항을 확인합니다.

PR 작성 후 같은 이슈에 대한 추가적인 코드 개선

PR을 작성 후 컨트리뷰터가 추가적인 오류나 코드 개선에 대해서 PR을 수정할 경우가 있습니다. 이때는 RP을 보낸 branch(develop-prtest1 branch)에서 commit, push하면 됩니다.

[vagrant@localhost Pull-Request-Test]$ vi modules/module/module.controller.php
[vagrant@localhost Pull-Request-Test]$ git add modules/module/module.controller.php
[vagrant@localhost Pull-Request-Test]$ git commit -m "module 모듈에 flag 추가"
[develop-prtest1 2cf4077] module 모듈에 flag 추가
 1 file changed, 2 insertions(+)
[vagrant@localhost Pull-Request-Test]$ git push origin develop-prtest1
 Username for 'https://github.com': akasima-pr-sender(GitHub ID)
 Password for 'https://akasima-pr-sender@github.com': (GitHub PassWord)
 Counting objects: 9, done.
 Delta compression using up to 2 threads.
 Compressing objects: 100% (5/5), done.
 Writing objects: 100% (5/5), 487 bytes | 0 bytes/s, done.
 Total 5 (delta 4), reused 0 (delta 0)
 To https://github.com/akasima-pr-sender/Pull-Request-Test.git
 af7c490..2cf4077  develop-prtest1 -> develop-prtest1
[vagrant@localhost Pull-Request-Test]$

image15.png



이렇게 PR을 작성하는 방법에 대해서 알아 봤습니다.

PR은 컨트리뷰터 저장소의 특정 branch를 원본 저장소의 브랜치로 보냅니다.
간혹 commit을 보낸다고 생각하시고 이미 PR을 보낸 branch에서 다른 주제를 수정해서 보내는 경우를 볼 수 있습니다.
이렇게 작성 할 경우 이미 있던 PR에 해당 commit이 추가되어 수정 내용을 알 수 없게 됩니다.
이와 같은 이유로 develop branch에서 PR을 보내지 않습니다.

제목 최종 글 날짜
공지 XE1 신규 보안 취약점 신고 포상제 종료 안내   2019.10.23
공지 [중요!] Object 클래스의 이름 변경 안내(PHP 7.2 버전 호환성) [7] 2020.08.16 by 천재 2017.11.27
PHP4 및 PostgreSQL, SQLite, Firebird 지원 중단 안내. [6] 2012.08.24 by vibram five fingers 2012.01.04
XE 공식 매뉴얼 사용 권리 업데이트 [5] 2012.08.24 by vibram five fingers 2012.01.04
업로드 파일 사이즈 제한 해제 [2] 2012.08.24 by vibram five fingers 2012.01.05
XE core 10000리비전 돌파... [11] 2012.08.24 by vibram five fingers 2012.01.06
1월 11일, XE 공식사이트 DB 정기점검. [3] 2012.08.24 by vibram five fingers 2012.01.10
XE 1.5.1.3 및 Textyle Package 배포 [8] 2012.08.24 by vibram five fingers 2012.01.25
2012년 1월 공헌자/커미터 현황 [1] 2012.08.24 by vibram shoes 2012.01.25
XE 1.5.1.4 긴급 보안패치 [6] 2012.08.24 by vibram shoes 2012.01.28
XE 1.5.1.5 배포 [11] 2012.08.24 by vibram five fingers 2012.02.01
XE 1.6 베타 개발 계획 [29] 2012.08.24 by vibram shoes 2012.02.03
[완료]공식사이트 점검안내   2012.02.06
XE 1.5.1.6 긴급 보안패치 [9] 2012.08.27 by vibram five fingers 2012.02.06
XE 1.5.0.9 배포 [22] 2012.08.27 by vibram five fingers 2011.11.17
XE 사업자 간담회 재신청 부탁드립니다.   2012.06.04
XE 비즈니스 확산을 위한 사업자 간담회를 진행합니다. [4] 2012.08.27 by vibram five fingers 2012.05.30
XE 1.5 업데이트 지원 캠페인 진행 [19] 2020.03.14 by vibram five fingers 2012.05.23
1.5.2.5 배포(보안패치 포함) [19] 2012.08.27 by vibram shoes 2012.05.14
XE 1.6을 사용하기 위한 PHP Version에 대해 알려 드립니다. [12] 2020.03.14 by vibram shoes 2012.05.08
[완료]공식사이트 점검 안내 [4] 2020.03.14 by vibram shoes 2012.04.02
제3회 XE사용자 공모전 디자인 부문을 개최합니다. [3] 2012.08.27 by vibram five fingers 2012.03.30