- 목표: 협업을 위한 기능들을 학습
- Git 설치
- Github
- SourceTree 설치 → History 보기 편함
git init // git이 이 디렉터리를 관리
git add // 변경사항에 대해서 git이 추적
git commit // 변경사항에 대해서 작업을 확정
git remote add 별명 [git repository 주소] // 현재 디렉터리를 git repository에 연결
git branch -M master // master branch 생성
git push 별명 master // master branch git repository에 업로드
-
branch의 사용 이유
- master branch는 현재 운영 중인 서비스의 소스코드로 사용되기 때문에
- 협업을 하는 경우
-
branch 기본 명령어
git branch // 현재 branch 확인 git branch [branch 명] // branch 생성 git checkout [branch 명] // branch 변경 -
merge 명령어
git checkout master git merge [병합할 branch 명]
-
PR이 필요한 이유
- 협업에서 master branch에 merge를 사용하기 위해 필요
-
PR을 사용한 업무 Flow
- local - 새로운 작업 branch에서 코드 작성
- local - 작업 완료 후 commit, push
- Github - 새로운 branch push 시, 저장소에 PR 만들기 버튼 표시
- Github - PR 생성
- Github - PR 메뉴에서 PR을 확인, 협업자들이 코드 리뷰 진행
- Github - merge 하기 버튼 클릭
- Github - master branch에 새로운 기능 적용
-
rebase 사용 이유
- commit을 재배치하기 위해서(PR이 안될 경우)
-
rebase 명령어
// 충돌이 없는 경우(한 줄기) git checkout [병합할 branch 명] git rebase master // 충돌이 있는 경우(여러 줄기) git checkout [병합할 branch 명] git rebase master // 충돌로 인해서 rebase 실패 // 직접 충돌 코드 정리 git add . git rebase --continue
- 작업 Flow
- Github - 개발 진행할 repository fork
- local - fork한 repository를 local로 clone
git clone [fork한 내 repository 주소]- local - remote 명령어를 통해 upstream 생성
git remote add upstream [개발 진행할 repository 주소]- local - remote의 origin, upstream 확인
git remote -v- Github - 개발 프로젝트 내 작업할 issue 생성(티켓 생성)
- local - 작업 branch 생성
- local - 작업 후 commit
- local - 내 repository로 push
- Github - PR 생성 후 merge 완료
- local - master branch upstream pull 진행 후, origin의 master push 진행(origin 최신 소스 유지)
-
stash 명령어
- 사용 이유: commit하기 전에 branch 변경 시
- 명령어:
git stash // 현재 작업 내용 임시 저장 git stash list // 임시 저장된 list 확인 git stash pop // 마지막에 저장한 작업 불러오기 git stash apply stash@{번호} // 특정 작업 불러오기 -
branch 전략과 git flow 사용