Git Branch

이재철·2022년 10월 27일
0

📄 Branches (브랜치)

  • 간결하고 잘 설명될 수 있는 이름을 선택
	# good
    $ git checkout -b oauth-migration
    
    # bad
    $ git checkout -b login_fix
  • 외부 서비스(github, jira)의 티켓(할일, 이슈)에 해당하는 이름도 브런치 이름으로 쓰는데 좋은 예시
	# good
    $ git checkout -b issue-15-oauth-migration
    
    # bad 무엇인지 알수 없음
    $ git checkout -b issue-123
  • 단어를 분리하기 위해 이음표(-) 사용

📄 Group Branches (그룹 브랜치)

  • 큰 기능을 작은 기능으로 분리하여 개발할 경우 큰 기능에 해당하는 branch를 작은 기능을 묶는 group branche로 활용
  • 계층적인 구조의 branch를 구성할 때 slash(/)를 사용하여 file system이나 URL 구조와 유사한 형태로 구성할 수 있음
    • Parent branch는 base의 고정된 이름을 사용
    • child branch는 base가 아닌 이름을 사용
    • child branch 상대적인 정의이므로 또 다른 children branch를 갖는다면 parent branch가 될 수 있음
종류형식예시
Parent branch<parent-branch-name>/basegit checkout -b feature-a/base
Child branch<parent-branch-name>/<child-branch-name>git checkout -b feature-a/sub-feature-x feature-a/base
git checkout -b feature-a/sub-feature-y feature-a/base
git checkout -b feature-a/sub-feature-z feature-a/base

📄 Branch 제거

  • 브런치가 merge된 이후 (남길 이유가 없다면) branch를 삭제
    • 작업이 완료되어 base branch로 merge한 branch
    • 작업이 취소되어 base branch로 merge되지 않는 branch
    • 다른 branch에 흡수 통합된 branch
    # master branch에 합쳐진 브랜치를 확인하기 위한 명령어
	$ git branch --merged | grep -v "\*"

📄 개인 브런치는 가능한 깔끔하게 정리

  • push하지 않은 local repository상의 branch나 push했더라도 다른 사람과 공유하지 않는 branch는 commit을 최대한 깔끔하게 정리
  • commit --amend를 사용하여 의미없는 commit 생성방지
  • 의미없는 commit이 많이 생성된 경우 squash를 이용하여 commit을 하나로 merge
  • Base branch가 전진하는 등의 이유로 작업 중인 branch로 merge할 때 Rebase를 사용하여 commit history를 선형으로 만듬

참조 url

profile
혼신의 힘을 다하다 🤷‍♂️

0개의 댓글