Woopii Vyeolog

[Git] 내가 자주쓰는 Git 명령어 모음 본문

Git, Github

[Git] 내가 자주쓰는 Git 명령어 모음

WooPii 2024. 3. 4. 19:18

Git 명령어 모음

  • 클론 생성
    • git clone {원격 저장소 URL} {복사할 디렉토리 경로} 
    • 예시) git clone https://github.com/사용자명/저장소명.git /Users/사용자명/내문서/프로젝트
  • Git Pull
    • git fetch origin
    • git pull
  • 원격 브랜치를 로걸 저장소로 생성
    • git checkout -b {생성할 브랜치명} {원격 브랜치명}
    • 예시) git checkout -b feature/payment origin/feature/payment
  • 로컬 브랜치 생성
    • git branch {생성할 브랜치명} {생성 기준이 되는 브랜치명}
    • 예시) git branch feature/test develop
  • 변경 내용 add, commit
    • git add {파일경로}, (전체는, git add -A, 현제 디렉토리는 git add .)
      • 변경내용 되돌리기 git rm --cached {파일명}
    • git commit -m {커밋 문구}
  • 원격 브랜치에 push
    • git push origin {push 대상 브랜치}
  • 특정 브랜치에 머지
    • git switch {merge 당할 브랜치}
    • git merge {merge할 내용이 있는 브랜치}
  • stash 하기
    • 목록 보기 : git stash list
    • 저장 : git stash save {stash 저장 문구}
    • 적용하기 : git stash apply {stash name}
    • 예시 : git stash apply stash@{0} ---(0이 최신, 1,2,3,4....이렇게 쌓임)
  • 특정 파일 변경분 롤백
    • git restore {파일경로}
    • 예시) git restore src/main/java/com/woopi/boilerplate/domain/image/image_file/ImageFileController.java
    • git checkout HEAD -- {경로}
    • 예시) git checkout HEAD -- src/main/java/com/woopi/boilerplate/domain/image/image_file/request/service/ImageFileGetCommand.java
Comments