branch 관리
branch는 기본적으로 스냅샷의 포인터를 변경하는 기능이다.
하지만 여러 포인트를 생성, 삭제 및 병합 등에서 관리가 필요하다(충돌이라던가 충돌이라던가…).
생성&삭제
git branch <name>: name이란 이름의 branch 생성- branch의 이동은 일어나지 않음
git branch -d <branch>: branch 삭제

이동
git switch <branch>|git checkout <branch>switch와checkout의 차이점switch는 오직 branch 관련 기능,checkout은 branch, file, commit 등- branch 기능만 보면 둘의 차이는 없다
git switch -c <branch>|git checkout -b <branch>: 브랜치 생성&이동
옵션
-v: 마지막 커밋을 보여줌
--merged: merge가 실행된 branch
--no-merged: merge가 아직 실행되지 않은 branch
git branch -v
$ git branch -v
iss53 93b412c fix javascript issue
* master 7a98805 Merge branch 'iss53'
testing 782fd34 add scott to the author list in the readmes
git branch --merged (branch): ”*“ 표시된 branch로 이동이 완료된 branch 목록- (branch) 기준이며, 생략 시 현재 위치한 branch를 기준
git branch -d <branch>로 삭제가 가능
$ git branch --merged
iss53
* master
git branch --no-merged (branch)- 기준은 –merge와 동일
- merge가 아직 실행되지 않은 branch
git merge --squash <branch>의 경우 merge 실행 후에도 no merge 상태git branch -D <branch>로 삭제 가능(-d옵션으로는 삭제 불가)
$ git branch --no-merged
testing
merge
branch 관련 오류의 원흉
fast-forward, 3-way merge가 있다.
- fast-forward : 스냅샷의 분기점이 없는 경우
- 새로운 branch 생성 후 기존 branch의 변경사항이 없는 경우
- 단순히 포인터만 옮기는 경우며, merge commit 미생성
- 단
--no-ff옵션을 줄 경우 merge commit생성

출처: https://stackoverflow.com/questions/6701292/git-fast-forward-vs-no-fast-forward-merge
$ git checkout master
$ git merge hotfix
Updating f42c576..3a0874c
Fast-forward
index.html | 2 ++
1 file changed, 2 insertions(+)
- 3-way merge : ff와 달리 합치려는 두 branch 모두 변경사항이 존재하는 경우
- merge를 시행했다고 알리는 merge commit 생성
- 충돌 발생 시 merge 중단


$ git checkout master
Switched to branch 'master'
$ git merge iss53
Merge made by the 'recursive' strategy.
index.html | 1 +
1 file changed, 1 insertion(+)
- 충돌 발생 시 다음과 같이 충돌이 발생한 영역을 표시하며
- 어떤 부분을 적용하고 버릴 지 선택
<<<<<<< HEAD:index.html
<div id="footer">contact : email.support@github.com</div>
=======
<div id="footer">
please contact us at support@github.com
</div>
>>>>>>> iss53:index.html
merge 옵션
git merge (--ff) <branch>: fast-forward일 시 merge commit 미생성, 기본 값git merge --no-ff <branch>: 강제로 merge commit 생성git merge --squash <branch>: <branch>의 commit, merge commit 미생성- 즉 2 branch를 합치고 stage 상태
- merge 후 commit 생성 필요
- –merged 상태 미갱신, 삭제 시
-D옵션 필요

출처: https://wikidocs.net/153871
Gitflow
기능 및 목적에 따른 branch 생성 방법.
master, main
완성된, 바로 배포가능한 상태.
Git의 경우 main이 기본값이며, GitHub의 경우 master가 기본값이다.
이름에 의미는 없으나(다만 master는 부정적인 의미가 있다나..), 로컬과 remote간의 이름을 통합시켜야 한다.
develop
기능 개발을 위한 브랜치들을 병합하기 위해 사용.
평소에 개발을 진행하는 branch이며, 모든 기능이 추가 및 버그가 수정되면 master (main)에 병합시킨다.

출처: https://gmlwjd9405.github.io/2018/05/11/types-of-git-branch.html
feature
새로운 기능 개발 및 버그수정을 위한 branch.
일반적으로 로컬에서 관리하며, remote 저장소에 공유하지 않는다.
개발이 완료될 시 develop에 병합시킨다.
feature/<name>
출처: https://gmlwjd9405.github.io/2018/05/11/types-of-git-branch.html
release
배포를 위한 전용 브랜치를 사용함으로써 한 팀이 해당 배포를 준비하는 동안 다른 팀은 다음 배포를 위한 기능 개발을 계속할 수 있다.
- 배포할 수준의 기능이 모이면 develop에서 분기
- 배포를 위한 최종적인 버그 수정, 문서 추가 등 릴리스와 직접적으로 관련된 작업을 수행
- 일반적으로 새로운 기능(feature)을 추가 병합(merge)하지 않음
- 최종적으로 배포가능한 상태가 되면
- master(main) 및 develop 브랜치에 병합
- merge commit에 Release 버전 태그를 부여
- 이름 규칙
- release-RB_* 또는 release-* 또는 release\/* 처럼 이름 짓는 것이 일반적인 관례
- [release-* ] 형식을 추천(EX) release-1.2)
출처: https://gmlwjd9405.github.io/2018/05/11/types-of-git-branch.html
hotfix
배포한 버전에 긴급하게 수정을 해야 할 필요가 있을 경우, master(main) 브랜치에서 분기하는 브랜치.
- 최대한 빠른 수정이 필요할 경우
- 수정 완료 후 master(main) 과 develop에 병함
- [hotfix-* ] 형식을 추천 EX) hotfix-1.2.1

출처: https://gmlwjd9405.github.io/2018/05/11/types-of-git-branch.html
C
Contents
