Git & Github

i33W·2022년 8월 2일
0

▶ git & github

  1. git 셋팅
    git --version
    git config --global user.email "hwangbomee@kakao.com"
    git config --global user.name "i33W"
    git config --global init.defaultBranch main

  2. git staging
    git add 파일명
    git add 파일명1 파일명2
    git add .
    git restore --staged 파일명

  3. git commit
    git commit -m "커밋 메세지"

  4. git status
    git status

  5. git log
    git log --all --oneline
    git log --all --oneline --graph

  6. git diff
    git diff
    git diff 커밋아이디
    git diff 커밋아이디1 커밋아이디2
    git difftool
    git difftool 커밋아이디
    git difftool 커밋아이디1 커밋아이디2
    git config --global diff.tool vscode
    git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'

  7. git branch
    git branch 브랜치명
    git switch 브랜치명
    git switch -c 브랜치명
    git merge 브랜치명
    git merge --squash 브랜치명
    git branch -d 브랜치명(병합0)
    git branch -D 브랜치명(병합X)
    git rebase 브랜치명
    git checkout -t [원격 브랜치명]

  8. git 파일 되돌리기
    git restore 파일명
    git restore --source 커밋아이디 파일명

  9. git 커밋 되돌리기(커밋 삭제x)
    git revert 커밋아이디
    git revert 커밋아이디1 커밋아이디2

  10. git 모든 걸 되돌리기
    git reset --hard 커밋아이디 (걍 암껏도 없음)
    git reset --mixed 커밋아이디 (staging된 상태, commit만 하면 됨)
    git reset --soft 커밋아이디 (staging 안되고 파일은 있음, add, commit 해야함)

  11. git 원격저장소에 올리기
    git push -u 원격저장소주소 main
    git remote add origin 원격저장소주소
    git clone 원격저장소주소
    git fetch 원격저장소주소 (원격저장소에 있는 commit 중에 로컬에 없는 신규 commit을 가져와)
    git pull 원격저장소주소 (git fetch + git merge 한 것)
    git push 원격저장소주소 로컬브랜치명

  12. git stash
    git stash (추적중인 파일은 다 이동됨, 신규 파일인데 staging 안되면 추적중 아니니까 이동 안됨)
    git stash save "메세지"
    git stash list
    git stash pop
    git stash drop 삭제할아이디
    git stash clear
    git stash -p

  13. git 원격저장소 정리하기
    git fetch origin
    git remote prune origin

  14. git 특정 커밋에 태그 생성
    git tag <tag_name> <commit_hash>


🚀 git 3가지 영역

Working Directory -(git add)-> Staging Area -(git commit)-> Repository(=.git 폴더)


🚀 merge 방법

(3-way merge, fast-forward merge, rebase and merge, squash and merge)

  • 3-way merge:
    각 브랜치에 신규 commit 1회 이상 있는 경우 두 브랜치 코드를 합쳐서 신규 commit을 자동 생성
    git switch main
    git merge 브랜치명

  • fast-forward merge:
    기준 브랜치에 신규 commit 없고, 새 브랜치에만 commit이 있을 때 신규 commit 없이 그냥 붙음(이거 싫으면 git merge --no-ff 하면 됨)
    git switch main
    git merge 브랜치명

  • rebase and merge:
    새 브랜치에서 rebase하여서 새 브랜치 시작을 기준브랜치 끝으로 이동 후 ff merge
    git switch 새브랜치
    git rebase main
    git switch main
    git merge 새브랜치

  • squash and merge:
    기준 브랜치에서 --squash 옵션 넣어서 merge하면 새 브랜치 변경 사항 전부를 하나의 commit으로 merge 할 수 있음
    git switch main
    git merge --squash 브랜치명
    git commit -m '메세지'


🚀 git Pull requests

  • 이거 꼭 github에서 하기!

🚀 git 개발 전략 (git flow, trunk-based)

  • git flow
  1. main 브랜치
  2. develop 브랜치 (개발용)
  3. feature 브랜치 (develop에 기능추가용)
  4. hotfix 브랜치 (main 브랜치 버그해결용)
  5. 가끔 release 브랜치 (develop 브랜치를 main 브랜치에 합치기 전에 최종 테스트용)
  • trunk-based
  1. main 브랜치
  2. feature 브랜치
profile
더 오래하면 돼.

0개의 댓글