거북목개발자

Git Branch 생성, 확인, 전환, 삭제, 원격 저장소에 push 본문

Git & Github

Git Branch 생성, 확인, 전환, 삭제, 원격 저장소에 push

거북목개발자 2022. 6. 22. 03:10
728x90

브랜치 생성 ($ git branch <branchName>)

$ git branch <branchName>

브랜치 확인 ($ git branch)

실행

$ git branch

실행 결과

$ git branch
  MySQL-BackUp
  develop
* feature/#18
  feature/#19
  main

git branch 명령어를 통해 MySQL-BackUp, develop, feature/#18, feature/#19 main 브랜치가 존재하는 것을 알 수 있다.

현재 브랜치는 *이 붙어있는 feature/#18이다.

브랜치 전환 ($ git chackout <branchName>)

실행

$ git checkout feature/#19

실행 결과

yoon2@TaeyoonKwon MINGW64 /c/study/DDP (feature/#18)
$ git checkout feature/#19
Switched to branch 'feature/#19'
Your branch is up to date with 'origin/feature/#19'.

yoon2@TaeyoonKwon MINGW64 /c/study/DDP (feature/#19)
$ git branch
  MySQL-BackUp
  develop
  feature/#18
* feature/#19
  main

현재 브랜치(*)이 feature/#19로 변경된 것을 확인할 수 있다.

브랜치 생성 + 전환 ($ git chackout -b <branchName>)

브랜치 생성과 checkout을 한꺼번에 수행

실행

$ git checkout -b feature/#20

실행 결과

yoon2@TaeyoonKwon MINGW64 /c/study/DDP (feature/#19)
$ git checkout -b feature/#20
Switched to a new branch 'feature/#20'

yoon2@TaeyoonKwon MINGW64 /c/study/DDP (feature/#20)
$ git branch
  MySQL-BackUp
  develop
  feature/#18
  feature/#19
* feature/#20
  main

feature/#20 branch가 생성되고 해당 branch로 checkout(이동)한 것을 알 수 있다.

브랜치 삭제 ($ git chackout -D <branchName>)

실행

$ git branch -d feature/#20

실행 결과

yoon2@TaeyoonKwon MINGW64 /c/study/DDP (feature/#18)
$ git branch -d feature/#20
Deleted branch feature/#20 (was 56cd03d).

yoon2@TaeyoonKwon MINGW64 /c/study/DDP (feature/#18)
$ git branch
  MySQL-BackUp
  develop
* feature/#18
  feature/#19
  main

위에서 생성한 feature/#20 브랜치가 삭제된것을 확인할 수 있다.

원격 저장소에 브랜치 push

$ git push origin <branchName>

로컬에 생성된 브랜치를 원격 저장소(github)에 push하는 것이다.

728x90
Comments