git 공부하면서 느낀 점 : 그동안 이거 모르고 어떻게 개발했는지 모르겠다. CLI(Command Line Interface) 로는 모든 git 기능을 사용할 수 있고, github 나 IDE 에서 제공하는 기능에는 한계가 있다. 그리고 GUI 기능도 CLI 를 사용할 줄 알아야 더 잘 사용할 수 있다.
초기 설정 : 깃 저장소를 만들거나(init) 가져온다.(clone) 초기에는 commit 시 기록될 기여자(contributor)의 정보도 입력한다.
git config --global user.name=
git config --global user.email=
git init
git clone \[dir name\]
git config --global alias. # 단축 명령어
git config --global pull.rebase true # pull 할 때 자동으로 rebase
.git/hooks # 깃 훅
상태 확인
git status // 파일 상태 확인 (modified, staged files) modified -> staged -> commit 순서
git log [--oneline] [-숫자] // 간결하게 보기, 숫자만큼의 커밋만 보기
commit 하기
git add // tracking, staging, resolving
git commit -m '커밋 내용' [-a] // -a : add 생략(추적중인 파일 자동 커밋)
git mv // 이름 변경
git diff --staged(cached) // 변경 내용 확인
git rm [--cached] // 그만 추적하기 cached : 로컬에서는 파일을 삭제하지 않음.
.gitignore // 추적하지 않을 파일 설정, directory/, glob 패턴
git commit --amend // 이전 커밋에 추가
git reset HEAD // staged -> working directory
git checkout <--file> // 파일 변경전으로 되돌리기
remote 저장소
git remote [-v] // 원격 저장소 확인
git fetch [remote] // 변경 내역 다운로드
git pull // git fetch + git merge
git push [remote] [branch] // commit 내역 remote 에 업로드
git remote show
git remote rename
git tag // 태그 조회
git tag -a [checksum] [-m description] // 해당 커밋 기준으로 태그 생성
git tag // pointer
git push <remote> <tag>
git push <remote> --tags // 모든 태그 push
branch
git branch [branch] // 조회, 생성
git checkout [-b] // b : (없으면)브랜치 만들고
git merge // 현재 브랜치로 merge, 충돌시 unmerged file 수동으로 변경
git branch -d // 삭제
git branch --merged // 삭제해도 되는 (이미 합쳐진)브랜치
git switch -c <branch> --track <remote>/<branch> // branch가 원격에만 존재할 때 로컬에 생성 및 이동
git brach -u <remote/branch>
git branch -vv // 추적중인 브랜치 조회
git push --delete // remote branch 삭제
git rebase ; git checkout ; git merge // A를 B에 merge, B가 남는 브랜치
git rebase --onto // branchA 에 branchC 를 rebase (rebase 공통 조상의 기준은 branchB 와 branchC)
// push 된 코드를 rebase 하는 건 죄악이다.
참고자료
Git - Book
git-scm.com
woowabros.github.io/tools/2017/07/12/git_hook.html
훅으로 Git에 훅 들어가기 - 우아한형제들 기술 블로그
들어가며…
woowabros.github.io
P.S. 협업하면서 느낀 점
git checkout --track <remote>/<branch> 이거 무조건 씀
node 기반이면 npm install 하다가 pakage-lock.json modified 돼서 commit 없이 원래 내 브랜치로 checkout 못 하는 경우 생김
그리고 rebase 자꾸 실패 뜨던데 왜일까...? 그래서 결국 merge 함
'공부 > 개발 & 컴퓨터' 카테고리의 다른 글
리팩터링 2판 (Refactoring) (0) | 2022.01.03 |
---|---|
github + slack 연동하기 (webhook) (0) | 2021.12.03 |
GitHub + Slack Webhook 400 오류 (0) | 2021.12.03 |
한 번에 끝내는 Git 사용법 - 이론편 (0) | 2021.09.25 |
한 번에 끝내는 Git 사용법 (feat. GitHub) - 실전편 (5) | 2021.09.25 |