git branch 이해하기

test·2021년 10월 8일

git

목록 보기
6/10
post-thumbnail

git branch 명령어

  • branch 확인(local and all)
git branch
git branch --all
  • branch 이동, 생성 및 이동
git switch BRANCHNAME
git switch -C BRANCHNAME2
  • switch 와 비슷한 명령어 checkout
git checkout HASHCODE(hashcode)
git checkout master(branch name)
git checkout -b BRANCHNAME(create and move)
  • 간단하게 최신 commit 확인 및 merge 확인
git branch -v
git branch --merged
git branch --no-merged(not merged)
  • branch 삭제 및 이름 변경, 변경된거 푸쉬
git branch -d BRANCHNAME
git branch --move name newName
git push --set-upstream origin newName
  • branch 사이 log 확인
git log master..test
git hist master..test
git diff master..test
  • fast-forward

    master 브랜치에서 branch 생성 이후 master branch 변동사항이 없다면 merge를 할 때 master branch 를 기존 branch로 옮기고 branch 삭제 하면 깔끔하게 fast-forward

  • fast-forward 하기싫을때(history 남기고 싶을때), 브랜치는 삭제되지만 기록에는 남아있음

git merge --no-ff BRANCHNAME
git branch -d BRANCHNAME
  • three-way merges -> 새로운 merge commit이 생성된다
git merge branchName

*conflict 해결 후 진행(파일에서 수정 후 수정파일 add

git merge --continue
  • merge 취소
git merge --abort
  • mergetool 원본파일 안보게 설정
git config --global mergetool.keepBackup false
  • rebase(새로운 commit 으로 생성된다)
git checkout branchA
git rebase master
git checkout master
git merge branchB
git branch -d branchA
git branch -d brachB
  • rebase --onto(branchA에 있는 branchB를 master branch 파생으로 옮기기)
rebase --onto master branchA branchB
git checkout master
git merge branchB

*cherry pick(git master branch에 원하는 commit 가져오기)

git cherry-pick HASHCODE
profile
bedev

0개의 댓글