brunch

You can make anything
by writing

C.S.Lewis

by 이승현 Jul 24. 2017

Git flow

공개된 프로젝트의 소규모 인원을 대상으로 한 Git flow

Git flow


공개된 프로젝트의 소규모 인원을 대상으로 한 Git flow입니다.

#01 Git flow
# Forking a project
# Create a Branch
$ git clone <forked url>
$ cd <project directory>
$ git checkout -b feature

# Make and commit changes
$ git add <files>
$ git commit

# Pulling from Official branch
$ git remote add official <official url>
$ git checkout develop
$ git pull --rebase official develop
$ git checkout feature
$ git pull --rebase develop

# Pushing to Origin branch
$ git push origin feature

# Open a Pull Request
# Merge a Pull Request




1. Set Up Git


Git은 프로그램 등의 소스 코드 관리를 위한 분산 버전 관리 시스템입니다.  

Git 설치

Git 최초 설정




2. Create an Account


GitHub는 분산 버전 관리 툴인 Git을 사용하는 프로젝트를 지원하는 웹 호스팅 서비스입니다.  

Github 계정 생성, 기본 설정




3. Forking a Project


Fork는 특정 repository(원격 저장소)를 통째로 사용자 저장소에 복사해 줍니다. Repository를 fork 하면 원래 프로젝트에 영향을 미치지 않고 사용자 저장소에서 자유롭게 관리할 수 있습니다.

#02 Fork


Step 1. Click "Fork" button

#02-1 Click "Fork" button


Step 2. Forking a project

#02-2 Forking


#02-3 Forked project




4. Create a Branch


Origin 저장소의 프로젝트를 local 저장소에 복제(Clone) 합니다. 이를 기반으로 새로운 기능이나 이슈에 집중할 수 있는 feature 브랜치를 생성합니다.

#03 Create a Branch


Step 1. Copy to clipboard

#03-1 Copy to clipboard


Step 2. Open Git Bash and Paste the URL  


Git Bash 설치


local 저장소에 복제하기 위해서는 git clone PASTED_URL 명령을 이용합니다.  

$ git clone https://github.com/oemilk/ilovepooq.git
Cloning into...
remote: Counting objects: 10, done.
remote: Compressing objects: 100% (8/8), done.
remove: Total 10 (delta 1), reused 10 (delta 1)
Unpacking objects: 100% (10/10), done.


Step 3. Move to Project directory  

$ cd pooqV3-android-studio


Step 4. Create a Feature branch


새로운 branch를 생성하기 위해서는 git branch NEW_BRANCH 명령이나 git checkout -b NEW_BRANCH 명령을 이용합니다.

$ git branch feature/bookmark
$ git checkout feature/bookmark
Switched to a new branch "feature/bookmark"
$ git checkout -b feature/free_ui
Switched to a new branch "feature/free_ui"


feature 브랜치는 feature/ 수식어에 "_" 구분자를 통해 조합한 단어들을 이용하여 생성합니다. 

$ git branch
  master
  develop
  feature/age_restriction
  feature/bookmark
  feature/chromecast
* feature/free_ui
  feature/vod_thumbnail




5. Make and commit changes


수정한 파일을 feature 브랜치에 저장해야 합니다.

#04 Make and commit changes


Step 1. Checking the Status


파일의 상태를 확인하려면 git status 명령을 이용합니다. 수정(modified)된 파일 pooqV3/src/main/res/values/strings.xml과 생성되거나 삭제된 파일 

pooqV3/src/main/java/aot/AotTest.java을 확인할 수 있습니다.


$ git status
On branch feature
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

      modified:   pooqV3/src/main/res/values/strings.xml

Untracked files:
  (use "git add <file>..." to include in what will be committed)

      pooqV3/src/main/java/aot/AotTest.java

no changes added to commit (use "git add" and/or "git commit -a")


Step 2. Viewing Changes


단순히 파일이 변경됐다는 사실이 아니라 어떤 내용이 변경됐는지 살펴보기 위해서는 git diff 명령을 이용합니다.


$ git diff
diff --git a/pooqV3/src/main/res/values/strings.xml b/pooqV3/src/main/res/values/strings.xmlindex e737f58..c5914d0 100644
--- a/pooqV3/src/main/res/values/strings.xml
+++ b/pooqV3/src/main/res/values/strings.xml
@@ -586,8 +586,8 @@

-    <string name="title">old title</string>
-    <string name="subtitle">old subtitle</string>            
+    <string name="title">new title</string>
+    <string name="title">new subtitle</string>


Step 3. Tracking New Files


git add 명령으로 파일을 새로 추적할 수 있습니다.  

$ git add pooqV3/src/main/res/values/strings.xml
$ git add pooqV3/src/main/java/aot/AotTest.java
$ git status
On branch feature
Changes not be committed:
  (use "git reset HEAD <file>..." to unstage)

  new file:   pooqV3/src/main/java/kr/co/captv/pooqV2/aot/AotTest.java
 modified:   pooqV3/src/main/res/values/strings.xml


Step 4. Committing Changes


git commit 명령으로 add 한 파일들을 커밋합니다.  

$ git commit


Step 5. Edit commit message


Git 설정에 지정된 편집기가 실행되고, i 명령을 통해 commit message를 수정합니다.

제목 : 50자로 제한, 이슈 기반일 경우 대괄호[] 이용, 끝에 마침표를 넣지 않는다.
// 제목과 본문을 빈 행으로 분리
- 본문(필수) : 현재 코드의 문제점, 수정 사항
- 본문(선택) : 수정 사항이 일으킬 수 있는 잠재적 부작용, 이슈, 코드, 인력, 추가 내용
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch git_test# Changes to be committed:
#       new file:   pooqV3/.../new file
#       modified:   pooqV3/.../modified file#


1. 이슈 기반인 경우

[CTD-341] 연령 표시 추가/변경- 연령 표시 UI 추가.

- vod30 API 수정.


2. 이슈 기반이 아닌 경우

2:1 종횡비 기기 대응

- LG 기기만을 대상으로 영상 비율 조정.
- 화면 비율을 조정하는 기능에 영향을 줄 수 있음.
- LG 기기를 판단하는 코드를 완벽히 신뢰할 수 없음.


3. 제목만으로 표현이 가능한 경우

BaseActivity showToast 함수 추가


4. 하나의 코드 수정으로 여러 이슈가 해결된 경우

[PAQA-3838] 이전/다음 회차가 종료 10초 미만 남은 경우 이어 보기 재생됨

- [PAQA-3839] 영상 최초 재생 시 이어 보기 UI 노출
- [PAQA-3841] 다음 회차 없는 영상 종료 시 앱 종료
- 10초 미만 남은 경우 무조건 이어 보기 재생하도록 코드 상 정의됨.
- 10초 미만이 아닌 영상 종료 시 이어 보기 재생되도록 수정.


Step 6. Save commit message


commit message를 아래 절차를 통해 저장, 종료합니다.

1. Edition mode를 벗어나기 위해 Esc 버튼을 누릅니다.

2. 변경 사항을 저장하고 종료하기 위해 :wq를 입력합니다.




6. Pulling from Official branch


Official develop 브랜치에서 변경 이력들을 내려받아야 합니다.

#05 Pulling from Official branch


Step 1. Registering Official branch to remote


현재 등록된 remote를 git remote -v 명령을 통해 확인할 수 있습니다.  


$ git remote -v
origin  https://github.com/pooq-shlee/ilovepooq.git (fetch)
origin  https://github.com/pooq-shlee/ilovepooq.git (push)


Official remote가 등록되어 있지 않은 경우, git remote add REMOTE_NAME REMOTE_URL 명령을 통해 Official remote를 등록해 줍니다.  

$ git remote add official https://github.com/oemilk/ilovepooq.git


등록한 Official remote를 확인할 수 있습니다.  

$ git remote -v
official  https://github.com/oemilk/ilovepooq.git (fetch)
official  https://github.com/oemilk/ilovepooq.git (push)
origin  https://github.com/pooq-shlee/ilovepooq.git (fetch)
origin  https://github.com/pooq-shlee/ilovepooq.git (push)


Step 2. Switch to Local Develop branch


현재 브랜치를 Local Develop 브랜치로 전환합니다.  

$ git checkout develop
#05-1 Switch to Local Develop branch


Step 3. Pulling from Official branch to Local branch


Official develop 브랜치로부터 git pull --rebase REMOTE_NAME BRANCH 명령어를 통해 변경 이력들을 Local develop 브랜치에 내려받습니다.  

$ git pull --rebase official develop
#05-2 Pulling from Official branch to Local branch


Step 4. Switch to Local Feature branch


현재 브랜치를 Local Feature 브랜치로 전환합니다.  

$ git checkout feature
#05-3 Switch to Local Develop branch


Step 5. Rebasing from Develop branch to Feature branch


Step 2.로 인해 Local develop 브랜치에 변경이 있을 경우, git pull --rebase DEVELOP_BRANCH

명령어 롤 통해 Feature 브랜치에 변경 이력을 내려받습니다.  

$ git pull --rebase develop
#05-4 Rebasing from Develop branch to Feature branch


Step 5-1. Fixing Merge Conflict


Step 5. 과정에서 충돌(Conflict)이 발생할 수 있습니다.  

$ git pull --rebase develop
# CONFLICT (content) : Merge conflict in <some-file>
#05-5 Fixing Merge Conflict


git status 명령으로 충돌이 발생한 파일을 찾을 수 있습니다.  

$ git status
# Unmerged paths:
# (use "git reset HEAD <some-file>..." to unstage)
# (use "git add/rm <some-file>..." as appropriate to mark resolution)
#
# both modified: pooqV3/src/main/java/kr/co/captv/pooqV2/aot/AotTest.java


충돌이 일어난 파일 수정 후, 해당 파일을 추가하고 리베이스를 계속하면 됩니다.  

$ git add pooqV3/src/main/java/kr/co/captv/pooqV2/aot/AotTest.java
$ git rebase --continue


리베이스는 다음 커밋으로 넘어가고, 더 이상 충돌이 없다면 리베이스가 완료됩니다. 리베이스 중에 뭔가 잘못되었다면, 이전 상태로 되돌릴 수 있습니다.  

$ git rebase --abort




7. Pushing to Origin branch


Origin develop 브랜치에 변경 이력들을 Push 해야 합니다.

#06 Pushing to Origin branch


Step 1. Pushing to Local Develop branch


commit 한 변경 이력들을 Origin Feature 브랜치에 Push 합니다.  

$ git push origin feature
#06-1 Pushing to Local Develop branch




8. Open a Pull Request


Pull Reqeust를 통해 변경 이력들을 Official Develop 브랜치에 Merge 요청할 수 있습니다.

#07 Open a Pull Request


Step 1. New pull request


New pull request 버튼을 클릭합니다.

#07-1 New pull request


Step 2. Create pull request


base fork와 head fork 설정 후, Create pull request 버튼을 클릭합니다.

base fork: captv/pooqV3-android-studio / base: develop

head fork: pooq-shlee/pooqV3-android-studio / base : feature


#07-2 Create pull request


Step 3. Write Title and Comment


제목과 코멘트를 입력합니다.

issue가 등록된 url

- 수정 사항
- 추가 내용


#07-3 Write Title and Comment


Step 4. Set Reviewers and Assignees


Reviewers와 Assignees 설정 후, Create pull request버튼을 클릭합니다.

#07-4 Set Reviewers and Assignees


Step 5. Created pull request


#07-5 Created pull request




9. Merge a Pull Request


코드 리뷰가 끝나면 Pull request를 Official Develop 브랜치에 Merge 하게 됩니다.

#08 Merge a Pull Request


Step 1. Merged a Pull Request


Pull Request 상태가 Open에서 Merged로 변경됩니다.


Official Develop 브랜치에 해당 commit들이 반영됩니다.


Step 1-1. Fixing Merge Conflict


Step 1. 과정에서 충돌(Conflict)이 발생할 수 있습니다.

#08-1 Fixing Merge Conflict


현재 브랜치를 Local Develop 브랜치로 전환합니다.  

$ git checkout feature
#08-2 git checkout feature


Official develop 브랜치로부터 git pull REMOTE_NAME BRANCH 명령어를 통해 변경 이력들을 Local develop 브랜치에 내려받습니다.  

$ git pull official develop
#08-3 git pull official develop


충돌이 일어난 파일 수정 후, commit 합니다.  

$ git add .
$ git commit -m 'Resolved PR #n merge conflicts'
#08-4 git add and commit


Origin Develop 브랜치에 Push 합니다.  

$ git push origin feature
#08-5 git push origin feature




이 글은 아래 링크 내용들을 기반으로 작성했습니다.


http://pepa.holla.cz/wp-content/uploads/2016/01/Git-for-Teams.pdf





문서화한 규칙만 진짜 규칙이다.
문서로 만들지 않은 규칙이 있다면 프로젝트는 무질서하게 될 것이다.
그러니 프로젝트 기여자들이 따라야 할 정확한 절차를 문서에 적어두자.


Git for teams 책에 나온 문구입니다.

구두상 절차를 설명하고 이해시킬 수도 있지만, 그 과정에서 일어나는 오해나 실수로 인한 문제는 돌이킬 수 없기에 이러한 문서를 만드는 작업도 반드시 필요하다고 생각합니다.

작가의 이전글 All About Kotlin 후기
작품 선택
키워드 선택 0 / 3 0
댓글여부
afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari