본문 바로가기
Infra/Git

브랜치 관리(생성,삭제,이동)

by 골든크랩 2022. 8. 22.
728x90
반응형

git 으로 프로젝트를 관리하면 최초에 master 브랜치가 생성이 된다.

 

새로운 기능을 만들때는, 새로운 branch 를 만들고, 거기서 개발및 테스트를 진행하는게 안전하다.

그리고 검증이 되면, master에 합치도록 한다.

 

1. branch 생성

PS C:\Projects\GIT-TEST> git branch  add-style
PS C:\Projects\GIT-TEST> git branch
  add-style
* master                           <==========  현재의 브랜치란 의미
PS C:\Projects\GIT-TEST> 

 

2. 새 브랜치로 이동

PS C:\Projects\GIT-TEST> git checkout add-style
Switched to branch 'add-style'
PS C:\Projects\GIT-TEST> git branch
* add-style                         <========== 현재의 브랜치란 의미
  master

 

3. 새로운 파일을 생성후 상태보기

PS C:\Projects\GIT-TEST> git status
On branch add-style
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   index.html              <============= 수정된 파일

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        main.css                                    <============= 아직 추적기를 안단 파일

no changes added to commit (use "git add" and/or "git commit -a")
PS C:\Projects\GIT-TEST>

 

4. 스테이징에 올리기

PS C:\Projects\GIT-TEST> git add .
PS C:\Projects\GIT-TEST> git status
On branch add-style
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   index.html ==> 새 버전을 만들 준비가 되었다.
        new file:   main.css

PS C:\Projects\GIT-TEST> 

 

5. 새로운 버전 만들기

PS C:\Projects\GIT-TEST> git commit -m '스타일 추가'
[add-style 1464bc1] 스타일 추가
 2 files changed, 5 insertions(+), 1 deletion(-)
 create mode 100644 main.css
PS C:\Projects\GIT-TEST>

 

6. 이력 확인

PS C:\Projects\GIT-TEST> git log
commit 1464bc1f5aa7c860f44689cfbe08ddd8d0dcf7e8 (HEAD -> add-style)  <==== 현재 버전. 브랜치명은 add-style
Author: wizarddennis <travlInfo4you@gmail.com>
Date:   Mon Aug 22 17:17:49 2022 +0900

    스타일 추가

commit 0ad9d908cf46146b303b5df828f8e894f9b3381d (master)
Author: wizarddennis <travlInfo4you@gmail.com>
Date:   Mon Aug 22 14:23:02 2022 +0900

    타이틀 태그 수정

commit 518b4ee4953973c48e69e44322568a6baff15347
Author: wizarddennis <travlInfo4you@gmail.com>
Date:   Mon Aug 22 12:11:55 2022 +0900

    프로젝트 생성
PS C:\Projects\GIT-TEST> 

 

7. master 로 이동

PS C:\Projects\GIT-TEST> git checkout master
Switched to branch 'master'
PS C:\Projects\GIT-TEST>

 

8. 현재까지 만들어진 브랜지 확인

PS C:\Projects\GIT-TEST> git branch
* add-style
  master

 

9. add-style 로 이동

PS C:\Projects\GIT-TEST> git checkout add-style
Switched to branch 'add-styl

 

10. 새로운 브랜치 생성

PS C:\Projects\GIT-TEST> git branch remove-this
PS C:\Projects\GIT-TEST> git branch
* add-style
  master
  remove-this
PS C:\Projects\GIT-TEST>
PS C:\Projects\GIT-TEST>

 

11. 새로운 브랜치 remove-this 로 이동.

PS C:\Projects\GIT-TEST> git checkout remove-this
Switched to branch 'remove-this'
PS C:\Projects\GIT-TEST>

 

12. 새로운 브랜치 삭제
PS C:\Projects\GIT-TEST> git branch -d remove-this
error: Cannot delete branch 'remove-this' checked out at 'C:/Projects/GIT-TEST'
PS C:\Projects\GIT-TEST> 

 

본인 브랜치 안에서는 삭제가 안됨.

 

 

13. 다른 브랜치에서 삭제하기

PS C:\Projects\GIT-TEST> git checkout  master
Switched to branch 'master'
PS C:\Projects\GIT-TEST>
PS C:\Projects\GIT-TEST> git branch -d remove-this
error: The branch 'remove-this' is not fully merged.
If you are sure you want to delete it, run 'git branch -D remove-this'.
PS C:\Projects\GIT-TEST> git branch
  add-style
* master
  remove-this
PS C:\Projects\GIT-TEST> git branch -D remove-this
Deleted branch remove-this (was 1464bc1).
PS C:\Projects\GIT-TEST> git branch
  add-style
* master
PS C:\Projects\GIT-TEST

 

 

14. 브랜치 생성과 이동을 한방에 하기

PS C:\Projects\GIT-TEST> git checkout -b abc
Switched to a new branch 'abc'
PS C:\Projects\GIT-TES

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

728x90
반응형

'Infra > Git' 카테고리의 다른 글

버전 되돌리기  (0) 2022.08.22
브랜치 병합, 충돌 해결  (0) 2022.08.22
버전 생성  (0) 2022.08.22
git 설치하기  (0) 2022.08.21
Git SourceTree 배포하기  (0) 2022.05.16

댓글