오픈소스 프로젝트에 PR을 올리기에 앞서, 개발환경을 설정해 보겠습니다.
이전 포스팅에서 복사(fork)한 오픈소스 프로젝트를 작업하기 위해, 깃허브에서 프로젝트를 다운받아 줍니다.
$ git clone https://github.com/as-you-say/template-github.git
## Cloning into 'template-github'...
## remote: Enumerating objects: 665, done.
## remote: Counting objects: 100% (665/665), done.
## remote: Compressing objects: 100% (581/581), done.
## remote: Total 665 (delta 71), reused 650 (delta 65), pack-reused 0
## Receiving objects: 100% (665/665), 15.44 MiB | 8.85 MiB/s, done.
## Resolving deltas: 100% (71/71), done.
$ cd template-github
이어서 원래 있던 오픈소스의 저장소 주소를 하나 추가해 줍니다.
$ git remote add opensource https://github.com/HJ-Template/template-github.git
성공적으로 추가가 되었다면 git remote -v 명령어를 통해 다음과같이 나오는 것을 확인하실 수 있습니다.
여기서 opensource는 새로 등록한 깃허브 저장소 이고, origin은 git clone 명령어를 통해서 프로젝트를 다운로드 받을 때, 자동으로 생성됩니다.
$ git remote -v
## opensource https://github.com/HJ-Template/template-github.git (fetch)
## opensource https://github.com/HJ-Template/template-github.git (push)
## origin https://github.com/as-you-say/template-github.git (fetch)
## origin https://github.com/as-you-say/template-github.git (push)
이것으로 개발환경 설정이 완료되었습니다!
이어서, opensource 저장소에 올릴 PR을 위해, 브랜치를 만들어 보겠습니다.
우선 브랜치를 만들기 이전에 git fetch 명령어로 opensource 저장소의 최신 코드를 불러옵니다.
$ git fetch opensource
$ git checkout master
$ git reset --hard opensource/master
이어서, git reset --hard 명렁어를 사용하여 opensource 저장소의 master 브랜치와 복사(fork)한 저장소의 master 브랜치를 일치시켜줍니다.
$ git checkout master
$ git reset --hard opensource/master
이제 새로운 기능을 개발할 브랜치를 만들어줍니다. 브랜치를 만드는 방법중 하나인 git checkout -b 를 사용하여 브랜치 생성과 동시에 그 브랜치로 이동하도록 합니다.
$ git checkout -b feature/newFunction
README.md 파일에 "새로운 기능 추가" 라는 문장을 추가한 다음 커밋을 해 보도록 하겠습니다.
$ echo "새로운 기능 추가" >> README.md
$ git add README.md
$ git commit -m '새로운 기능 추가'
##[feature/newFunction 013c445] 새로운 기능 추가
## 1 file changed, 4 insertions(+), 2 deletions(-)
이제 origin 으로 등록되어있는 저장소에 새로 개발한 브랜치(feature/newFunction)를 올려줍니다. 성공적으로 올라갔다면 아래와 같은 로그를 확인하실 수 있습니다.
$ git push origin feature/newFunction
## Enumerating objects: 5, done.
## Counting objects: 100% (5/5), done.
## Delta compression using up to 8 threads
## Compressing objects: 100% (3/3), done.
## Writing objects: 100% (3/3), 360 bytes | 360.00 KiB/s, done.
## Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
## remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
## remote:
## remote: Create a pull request for 'feature/newFunction' on GitHub by visiting:
## remote: https://github.com/as-you-say/template-github/pull/new/feature/newFunction
## remote:
## To https://github.com/as-you-say/template-github
## * [new branch] feature/newFunction -> feature/newFunction
이전에 복사한(fork) 저장소 페이지로 들어가서 Pull Request 탭을 클릭해 보시면 다음과 같은 화면을 보실 수 있습니다. New pull request 버튼을 눌러줍니다!
그리고, 다음과 같이 저장소와 브랜치를 선택한 다음 Create pull request 버튼을 눌러줍니다.
opensource로 등록한 주소에서 확인하실 수 있습니다~
[Github 오픈소스 기여방법] 오픈소스 프로젝트 복사하기 (fork) (0) | 2021.07.09 |
---|---|
[Github 오픈소스 기여방법] 오픈소스란? (0) | 2021.07.09 |