-
Git - Branch 설명 및 실습Git 2023. 7. 19. 10:38반응형
Branch 설명 및 실습
Branch
프로젝트를 하나 이상의 모습으로 관리해야 할 때
여러 작업들이 각각 독립되어 진행될 때
branch를 분리한다면 하나의 프로젝트폴더에서 진행이 가능하다.Branch 생성하기
git branch add-"[branch 명]"
ex) git branch add-coachBranch 목록 확인하기
git branch
Branch 이동
git switch "[이동할 branch 명]"
branch를 생성하고 생성한 branch로 이동하면 위의 그림과 같이 우측 파란색 글씨(branch)가 변경된 것을 확인 가능하다.
Branch 생성과 동시에 이동하기
git switch -c "[새로운 branch명]"
ex) git switch -c new-teamsBranch 삭제
git branch -d "[삭제할 branch명]"
ex) git branch -d to-deleteBranch 이름 변경
git branch -m "[기존 branch명]" "[변경 할 branch 명]"
ex) git branch -m to-delete to-erase
이제 생성한 각각의 branch에서 작업을 수행해보자.
1. main 브랜치
- Leopards의 members에 Olivia 추가
- 커밋 메시지: Add Olivia to Leopards
- Panthers의 members에 Freddie 추가
- 커밋 메시지: Add Freddie to Panthers
2. add-coach 브랜치
- Tigers의 매니저 정보 아래 coach: Grace 추가
- 커밋 메시지: Add Coach Grace to Tigers
- Leopards의 매니저 정보 아래 coach: Oscar 추가
- 커밋 메시지: Add Coach Oscar to Leopards
- Panthers의 매니저 정보 아래 coach: Teddy 추가
- 커밋 메시지: Add Coach Teddy to Panthers
3. new-teams 브랜치
- pumas.yaml 추가
- 커밋 메시지: Add team Pumas
team: Pumas manager: Jude members: - Ezra - Carter - Finn
- jaguars.yaml
- 커밋 메시지: Add team Jaguars
team: Jaguars manager: Stanley members: - Caleb - Harvey - Myles
결과 살펴보기
git log --all --decorate --oneline --graph
각 branch별로 커밋 현황확인이 가능하다.
좌측이 sourcetree로 확인한것이다.
눈으로 쉽게 보기에는 sourcetree가 더 편하니 해당 명령어가 있다는 정도만 알아두자.
반응형'Git' 카테고리의 다른 글
Git - Branch충돌 해결하기 (0) 2023.07.19 Git - Merge 와 Rebase 차이와 실습 (0) 2023.07.19 Git - Revert, Reset Sourcetree로 진행 (0) 2023.07.18 Git - 버전 되돌리기 Reset, Revert (0) 2023.07.18 Git - add, commit, 기본 실습 및 설명 (0) 2023.07.18 - Leopards의 members에 Olivia 추가