git 명령어 정리

git을 사용하긴 하지만 아직도 많은 부분이 어색하네요. 아래는 가끔씩 찾는 부분을 정리하는 내용입니다.

브랜치 삭제

  • local
git branch -d <branch_name>
git branch -D <branch_name> # 강제 삭제
  • remote
git push <remote_name> --delete <branch_name>

브랜치 변경

  • local
git checkout <branch_name>
  • 작성 및 변경
git checkout -b <branch_name>

cli 자동로그인(github)

git config credential.helper store

add 취소

# 모두 추가
git add *
# 취소하기
git reset HEAD
# 특정 파일(CONTRIBUTING.md)
git reset HEAD CONTRIBUTING.md

commit 취소

# log 확인
git log
# commit을 취소하고 unstaged 상태로 
git reset HEAD^

다른 branch 의 파일 가져오기

git branch master
git checkout <브랜치이름> <경로파일>

git file 삭제

git rm <파일이름>
git rm --cached <파일이름>   # 원격저장소의 파일만 삭제