git

Branch strategy

미분류

reference, revision, branch, tag

  • Git Refs

    • SHA-1(commit hash) 값보다 사용하기 쉬운 이름으로 된 포인터를 사용하기 위해 reference, refs를 사용한다.

    • .git/refs 디렉토리에 SHA-1 값을 외우기 쉬운 이름으로 된 파일에 저장한다.

      .git/refs 디렉토리 구조
      ./
      ├── heads/
      └── tags/
    • 변경 방법: git update-ref refs/heads/master cac0ca

    • HEAD 파일은 현 브랜치를 가르키는 간접(symbolic) Refs

      • refs를 가르키는 겂이라서 SHA-1 값을 저장하지 않는다.

        $ cat .git/HEAD
        ref: refs/heads/master
  • Revision

    • extended SHA-1 사용

  • Branch

    • 브랜치는 결국 어떤 작업 중 마지막 작업을 가르키는 포인터 or refs

  • Tag

    • Annotated 태그, Lightweight 태그로 나뉨

    • Lightweight 태그

      • 브랜치랑 비슷하지만 브랜치처럼 옮길 수 없음

Workflow

Cheat sheet

원격 브랜치를 로컬에 생성할 때

$ git remtoe update
$ git branch -r
  origin/develop
  origin/master
$ git branch -a
  * develop
  master
  remotes/origin/develop
  remotes/origin/master
$ git checkout -t origin/develop # develop으로 브랜치 생성됨
$ git branch -d master # master 브랜치 삭제

commands

checkout

Switch branches or restore working tree files

switch

Switch branches 2.23.0

restore

Restore working tree files 2.23.0

Description AS-IS TO-BE

신규 브랜치로 교체하기

git checkout -b <new_branch>

git switch -c <non_existing_branch>

기존 존재하는 브랜치로 변경하기

git checkout <existing_branch>

git switch <existing_branch>

원격 저장소 브랜치 가져오기

git checkout -b <new_branch> <origin_branch>

git checkout -t <origin_branch>

수정한 파일 되돌리기

git checkout — <file>

git restore <file>

스테이징 되돌리기

git reset HEAD <file>

git restore --staged <file>