2023.11.20(월)

✏️Git Branch Naming Conventions

  • Basic Rules
    • 소문자 사용 & 단어는 hyphen(-)으로 분리
      • ex) feature/new-login, bugfix/header-styling
    • 영문(a-z), 숫자(0-9), hyphen(-)만 사용, 그 외의 구두점, 공백, 밑줄 등 사용 X
    • 연속적인 hyphen 사용 X, branch 이름을 hyphen으로 끝내지 않기
    • branch에서 수행된 작업을 잘 설명하면서도 간결한 이름 사용
    • 일관성(Consistency)이 가장 중요!
  • Branch Prefixes : branch의 목적을 빠르게 식별하기 위해 사용
    Branch CategoryPrefixExamples
    Feature Branches (기능 개발)feature/feature/login
    feature/select-product
    Bugfix Branches (버그 수정)bugfix/bugfix/header-styling
    bugfix/issue-342/button-overlap-form-on-mobile
    Hotfix Branches (긴급 수정)hotfix/hotfix/critical-security-issue
    hotfix/v1.2.1
    Release Branches (출시 준비)release/release/v1.0.1
    Documentation Branches (문서 작성)docs/docs/api-endpoints
    • 위의 표 외에도 category는 다양할 수 있고 팀 내에서 규칙을 정하면 됨
      • ex) test, dev (develop), exp (experiment), refactor ...
    • Author Name(작성자 이름)을 붙이는 경우도 있음
      • ex) jaekyung.hwang-feature-checkout : jaekyung hwang이 해당 checkout feature 지점에서 작업했음을 암시
  • 참고자료

🕸️Git Flow (Git Branch Strategy)

➀ 3-way merge (non fast-forward)

  • 일반적으로 많이 사용하는 전략
  • 분기가 시작된 base를 기준으로 각 branch가 참조하는 commit을 고려하여 자동 병합을 진행
  • git merge --no-ff

Untitled

➁ Fast-forward merge

  • 뒤에 쳐진 branch의 HEAD를 앞서있는 branch의 HEAD로 이동
  • 마치 branch가 점프 하듯 상대 branch HEAD로 이동하는 모습을 본따 fast-forward(빨리 감기)라고 불림
  • feature branch의 세세한 commit log들이 main branch에 그대로 들어가기 때문에 commit log가 복잡해짐😑
  • git merge

➂ Rebase and merge

  • Establish a new base level (branch 시작점을 다른 commit으로 옮김)
  • 합쳐질 branch의 시작점을 main branch의 최신 commit으로 이동시키고(rebase) fast-forward merge
  • 3-way merge를 하지 않고도 깔끔하게 branch를 관리하므로 history나 log 확인이 쉬움
  • BUT conflict가 자주 일어남
  • git rebase

➃ Squash and merge

  • Crush or squeeze (something) with force so that it becomes flat
  • 별도의 log를 저장하거나 확인할 필요가 없을 경우 squash and merge를 적용하여 log 없이 변경 사항만 업데이트
  • 합쳐질 branch에서 만들어 놨던 commit들을 하나로 합쳐서 main branch에 새로운 commit 생성
  • 중요하지 않은 branch에서 사용
  • git merge --squash

📥GitHub GUI로 Pull Request & Merge

  • main branch 보호 → 여러 권한 설정 가능
    • Branch protection rule은 언제든지 수정/삭제 가능

    • 협업 시 필요

  • Pull Request = 추가 branch → main branch 병합 요청
    • PR message 잘 쓰기 (Markdown 사용 가능)

  • GitHub가 충돌이 일어나는지 확인해줌
    • merge 시 merge commit 잘 쓰기

참고 : [Git] Commit Message / PR 잘 쓰는 방법

  • 추가한 branch 삭제 (Restore branch 버튼으로 복구 가능) (revert?)

    • CLI에서는 git reflog로 commit과 HEAD 번호 확인 후 git checkout -b <branch이름> <HEAD@{숫자}> 🔗
  • Git에서 remote branch의 변경 사항 동기화

    • git fetch 🔗

      • 원격 저장소 또는 branch에 적용된 변경 사항 확인 가능

      • git pull과 비교했을 때 fetch는 변경 내용을 local에 반영하지 않지만, pull은 변경 내용을 local에 반영하기 때문에 주의해야 함

        mergepull 전에 fetch로 변경 사항을 먼저 확인하는 것이 안전

      • -p 또는 --prune(가지치기) tag로 remote에 더 이상 존재하지 않는 remote-tracking references 제거

        • ex) GitHub에서 GUI로 branch를 merge하고 삭제한 경우 git fetch -p로 local & remote branch 동기화
profile
이것저것 관심 많은 개발자👩‍💻

0개의 댓글