git을 개인프로젝트에 도입하고자, 기본적인 내용들을 정리해보려 한다.
오픈소스 프로젝트에서 기여를 하려면 어떤 플로우로 진행이 될까?
pull request을 구글링 하다가 좋은 튜토리얼 사이트를 발견했는데
설명서에 나와있는대로 따라하면 전반적인 플로우에 대해 알 수 있을 것이다.
기여하려는 대상repository를 나의 GitHub repository(내 원격 Repository)로 Fork한다.
내 원격 repository에 fork한 소스가 복사되어져 있는 것을 확인할 수 있다. (forked from ... 이 붙어있다.)
이 소스코드의 깃 주소를 복사한다.
https://github.com/this-is-you/first-contributions.git
그리고 작업하려는 로컬 경로로 이동하여
위에서 복사한 주소를 이용해 소스코드를 내려받는다.(clone)
아래 명령어에서 this-is-you 부분은 나의 GitHub username이다.
git clone https://github.com/this-is-you/first-contributions.git
clone한 소스코드 폴더로 이동을 한 후
cd first-contributions
변경작업을 위해 브랜치를 딴다. (clone한 원본소스는 보존)
git switch -c your-new-branch-name
// -c 옵션은 create의 약자
Contributors.md 파일에 자신의 GitHub username을 추가하여 저장한다.
그리고 변경사항을 내 원격 repository에 반영(push)하기 위한 commit을 만들기 위해 commit 리스트에 추가(add)한다.
(push는 커밋단위로 반영된다.)
git add Contributors.md
[add 전]
[add 후]
[add 후] 스냅샷을 통해 변경사항이 commit에 추가됨을 알 수 있다.
변경사항이 들어있는 commit을 내 로컬 repository에 제출(commit)한다.
git commit -m "Add your-name to Contributors list"
이제 내 원격 repository에 반영(push)할 commit이 준비되었다.
다음 명령어를 통해 push한다.
git push origin -u your-branch-name
// 1. origin이라는 원격 repository에 your-branch-name 이라는 브랜치를 생성하고
// 2. 로컬 repository your-bracnh-name 브랜치의 내용을 원격 repository your-branch-name 브랜치에 보낸다.
// -u 옵션을 쓰면 다음 push/pull 시에 source, destination 브랜치를 생략할 수 있다.
// -u 옵션은 --set-upstream 의 줄임말로 로컬 respository의 your-branch-name 브랜치가 원격 respository의 origin 브랜치를 항상 추적하도록(tacking)하도록 설정한다.
// 원격 repository origin 브랜치를 로컬 repository your-branch-name 브랜치의 업스트림(upstream) 브랜치 라고 한다.
[-u 옵션을 붙인경우] git push
[-u 옵션을 안붙인경우] git push origin master[souerce]:master[destination]
// '로컬 repository의 master브랜치(첫번째 master)'를 'origin 원격 repository의 master브랜치(두번째 master)'에 push한다.
[-u 옵션을 붙인경우] git pull
[-u 옵션을 안붙인경우] git pull origin master[destination]:master[source]
// 'origin 원격 repository의 master브랜치(첫번째 master)'를 '로컬 repository의 master브랜치(두번째 master)'에 pull한다.
GitHub repository(내 원격 repository)에 들어가보면
'Compare & pull request' 버튼이 활성화되어 있다.
이 변경사항을 '대상 repository' 반영을 하고싶다면(기여하고 싶다면)
'Compare & pull request'버튼을 눌러 변경사항을 제출한다.