Tip

[Git] 협업 시 task branch에 main branch 필요내용 불러오기

너드나무 2024. 7. 30. 18:14
반응형

서론

Git을 통해 제품에 대한 코드 형상 관리를 수행하면서 내 작업 기간과 겹쳐서 메인 branch에 PR이 Merge가 될 경우가 존재한다.

개발하고자 하는 branch와 별개의 영역에 대한 Merge 건이면 문제되지 않지만, 테스트 과정에서 필요한 코드가 올라오는 경우도 존재한다.

시나리오

  1. 카카오 알림톡 발송 버튼 UX/UI 개발 (Input: 휴대폰번호)
  2. kakao_alert Branch 생성 후 작업
  3. 프론트엔드에서 버튼에 대한 퍼블리싱 및 API 연동 개발 및 Merge (main)
  4. 동작 테스트 시 main 코드 병합 필요

Git Command

  • local 작업 내용 commit
% git add . 
% git commit -m "feat: 커밋 메세지"
[task_branch 71f03f0] feat: 커밋 메세지
 2 files changed, 9 insertions(+), 20 deletions(-)
  • main branch 변경 및 local pull
# main 브랜치 변경
% git checkout main 
Switched to branch 'main'
Your branch is behind 'origin/main' by 9 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)
  
# Remote main -> local main에 반영
% git pull origin main
 * branch            main       -> FETCH_HEAD
Updating 0232eee..9a35492
Fast-forward
 src/main/resources/static/index.html   |  93 ++++++++++++++++++++++++++++++++++++++++++++++-----
 src/main/resources/static/item.html    |   2 +-
 src/main/resources/static/src.html 	|  17 +++++-----
 src/main/resources/static/dst.html 	| 119 ++++++++++++++++++++++++++++++++++++++++++++++++++---------------
 src/main/resources/static/temp.html 	| 133 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
 5 files changed, 290 insertions(+), 74 deletions(-)
  • task branch rebase : 작업 이력을 main Branch 최신 commit 반영
% git checkout task_branch
Switched to branch 'task_branch'
Your branch and 'origin/main' have diverged,
and have 1 and 9 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

% git rebase main
Successfully rebased and updated refs/heads/task_branch.

 

  • Conflict 발생 시 해당 파일 작업 후 rebase 재시도
% git add 충돌난파일
% git rebase --continue
% git push origin task_branch
  • Task Branch pull 수행 후 Remote push
% git pull origin task_branch --rebase
From https://github.com/git_test.git
 * branch            bugo_setting -> FETCH_HEAD
warning: skipped previously applied commit 6bf783c
hint: use --reapply-cherry-picks to include skipped commits
hint: Disable this message with "git config advice.skippedCherryPicks false"
Successfully rebased and updated refs/heads/task_branch.

% git push origin task_branch 
Enumerating objects: 86, done.
Counting objects: 100% (86/86), done.
Delta compression using up to 12 threads
Compressing objects: 100% (61/61), done.
Writing objects: 100% (65/65), 12.39 KiB | 4.13 MiB/s, done.
Total 65 (delta 37), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (37/37), completed with 13 local objects.
remote: This repository moved. Please use the new location:
remote:   https://github.com/git_test.git
To https://github.com/git_test.git
   42f39de..2707dcb  task_branch -> task_branch

결론

  1. 작업 코드가 날아가도 내 것만 날아가면 다행이다.
728x90
반응형