[git] 명령어 정리
remote
- git remote -v: 연결된 git 저장소 확인
- git remote remove origin: 해당 git 저장소 연결 삭제
- git remote add <저장소명>
: 해당 git 저장소 로컬과 연결 저장소명>
add
- git add . : 가장 최근 변경된 내용 전부 stage에 올리기
- git add “파일명” : 해당 파일만 stage에 올리기
commit
- git commit —amend : 가장 최근 commit한 내역 수정 , 끝나면 esc - :wq
- git commit -m “메세지” : 해당 메시지로 변경 사항들 commit
push
- git push origin 브랜치명 : 연결된 github 저장소 해당 브랜치로 commit한 파일 전송
- git push -f origin 브랜치명 : 강제로 전송 (최악의 경우)
fetch
-
git fetch origin 브랜치명 : 해당 브랜치의 내용 다운 병합은 안됨
→ 충동 방지, 바뀐 내용만 확인 만약 괜찮으면 pull로 병합!
pull
- git pull origin 브랜치명 : 해당 브랜치의 내용으로 최신 업뎃 ( 파일 다운+ 병합)
merge
- git checkout 브랜치1 → git merge 브랜치2 : 브랜치1에서 브랜치2의 내용 병합( 팀원이 pull request하면 팀장이 이렇게 merge)
stash
- git stash : 코드 백업하기
- git stash drop: 최근 백업 코드 삭제
- git stash drop stash명 : 해당이름의 stash만 삭제
- git stash clear: 백업 전부 삭제
- git stash apply stash명: 원하는 stash 복구
만약 코드를 잘못된 branch에서 작성했을때 작성한 코드를 git stash로 백업 후, 원상태 복구하면 된다. 그리고 git checkout 원하는 브랜치명으로 전환한 뒤 백업코드를 해당 branch에서 복구하면 됩니다.
reset
- git reset HEAD^ : 가장 최근 push한 내역 삭제 → git push -f origin main 해서 github 저장소와 로컬 저장소 동일하게 만들어 주기 (나쁜 방법)
init
- git init: 로컬저장소에서 git 초기화
branch, checkout, switch
- git branch : 현재 자신과 연결된 branch 목록
- git branch -d 브랜치명 : 해당 branch 삭제
- git branch -D 브랜치명: 위명령어가 안들을 때 강제 삭제
- git branch 브랜치명 : 브랜치명으로 브랜치 생성
- git checkout 브랜치명 : 해당 브랜치로 전환
- git checkout -b 브랜치명 : 위 두 명령어 합친 것
- git switch 브랜치명 : 해당 브랜치로 전환
- git switch -c 블랜치명: 해당 브랜치명으로 새 브랜치생성
상태확인
- git status : 현재 로컬 저장소 변경내역, github 저장소와 상태차이 확인
- git log : push된 내역 일람
협업방식
✔ fork한 뒤 내 repo에서 작업 후 pull request하는 방법
Git을 이용한 협업: Fork 부터 Pull Request 까지
✔ collaborator: 같은 repo의 팀원 각각의 branch에서 작업후 pull request
[Git] Github 같은 저장소 함께 쓰기(feat.협업하기)
✔ pull request와 코드 리뷰
✔ commit msg 작성법
[Git] 규칙적인 Commit 메세지로 개발팀 협업하기👾
✔ pull request 작성법
github pull request template 만들기
참고
✔ git commit —amend —no-edit —date : commit 시간 바꾸기
댓글남기기