카테고리 없음

[Git] 주요 명령어 모음

erin.yoon 2020. 7. 10. 18:13

 

 

기본 명령어

  • git init : git 생성
  • git clone git_path : 원격저장소에서 코드 가져오기
  • git add file_path : 수정한 코드 선택 (git add *)
  • git commit -m "commit_message" : 선택한 코드 설명 적기
  • git push remote_name branch_name : commit한 코드 git server에 보내기 (git push origin master)
  • git config-global user.name "user_name" : git 계정 이름 변경
  • git config-global user.email "user_email" : git 계정 이메일 변경

 

Branch 관리하기 (협업할 때)

  • git branch branch_name : 브랜치 생성
  • git checkout branch_name : 브랜치 선택하기(checkout)
  • git checkout -t remote_path/branch_name : 원격 브랜치 선택
  • git branch -a : 로컬 브랜치 목록
  • git branch -r : 원격 브랜치 목록
  • git branch -m branch_name change_branch_name : 브랜치 이름 변경
  • git branch -d branch_name : 브랜치 삭제

 

pull VS fetch

  • git pull : git server에서 최신코드 받아와서 merge하기
  • git fetch : git server에서 최신코드 받아오기 (merge하지 않음!!)

 

Commit 취소하기

  • git reset : add한 파일 취소
  • git reset-hard HEAD^ : commit하기 이전의 코드로 돌아가기
  • git reset-soft HEAD^ : commit만 취소하고 코드는 살리기
  • git reset-merge : merge한 코드 취소하기
  • git reset-hard HEAD : HEAD를 기준으로 이전코드로 돌아가기 && git pull : git 코드 모두 강제로 받아오기

 

코드 잠깐 저장하고, 다른 브랜치로 이동하기

  • git stash : 코드를 stash 영역에 잠시 저장하기
  • git stash list : stash 영역 목록 확인(스택구조)
  • git stash/git stash save "message" : 작업코드 임시저장하고 브랜치 변경하기
  • git stash pop : 마지막으로 임시저장한 작업코드 가져오기
  • git branch-set-upstream-to=remote_path/branch_name : git pull no tracking info 에러 해결

 

 

 


출처 : pks2974님 medium t.ly/CVZ1

반응형