728x90
user
git config --global user.name "kim"
git config --global user.email "kim@example.com"
clone / remote
git clone git@bitbucket.org:org/repo.git
# 또는 새 저장소일 때
git init
git remote add origin git@bitbucket.org:org/repo.git
git fetch origin
git branch -M main
git push -u origin main
status check
git status
git diff # 워킹 vs 인덱스
git diff --staged # 인덱스(staged) vs HEAD
git log --oneline --graph --decorate -n 20
staging / unstaging
git add . # 변경 모두 스테이징
git add path/to/file
git restore --staged file # 스테이징 취소(인덱스→워킹으로)
git restore file # 변경 취소(워킹 파일을 HEAD로 되돌림)
commit
git commit -m "feat: add user API"
git commit --amend -m "fix: correct message" # 마지막 커밋 수정
git commit --fixup <commit> # 대상 커밋 보정용
git rebase -i --autosquash origin/main # fixup 자동 정리
branch / switch
git switch -c feature/login
git switch main
git switch - # 직전 브랜치로 토글
git branch -d feature/login
git branch -D feature/login
fetch / pull / push
git fetch origin --tags
git pull --ff-only # Fast-forward만 허용(우발 머지 방지)
git pull --rebase --autostash # 로컬 변경 자동 스태시 후 리베이스
git push
git push -u origin feature/x # 최초 푸시(업스트림 설정)
git push -u origin HEAD # 현재 브랜치를 동일 이름으로 푸시
merge / rebase
git merge --no-ff feature/x # 머지 커밋 보존
git rebase main
git rebase -i HEAD~5
git rebase --continue | --abort | --skip
공개 브랜치에서 히스토리 수정 후
git push --force-with-lease
되돌리기(Undo)
git reset --soft HEAD~1 # 커밋만 취소(변경은 staged 유지)
git reset --mixed HEAD~1 # 커밋만 취소(변경은 워킹에 남김, 기본)
git reset --hard HEAD~1 # 커밋+변경 삭제(주의)
git revert <commit> # 되돌리는 새 커밋(공유 브랜치에 안전)
스테시(임시 보관)
git stash push -m "wip: refactor"
git stash -u # Untracked 파일도 같이
git stash --keep-index # Staged는 유지
git stash -p # 부분 스태시
git stash list
git stash apply stash@{0}
git stash pop
log / search
git log --oneline --graph --decorate --all
git log -S "keyword" # 특정 문자열 추가/삭제된 커밋 찾기
git show <commit>
git blame path/to/file
git grep -n "keyword" # 워킹/인덱스/HEAD에서 문자열 검색
tag
git tag v1.0.0
git tag -a v1.0.0 -m "release 1.0.0"
git push origin v1.0.0
git push origin --tags
git tag -d v1.0.0 # 로컬 태그 삭제
git push origin :refs/tags/v1.0.0 # 원격 태그 삭제
원격/브랜치 관리
git remote -v
git remote set-url origin git@bitbucket.org:org/repo.git
git branch -r # 원격 브랜치 목록
git push origin --delete feature/x # 원격 브랜치 삭제
git fetch -p # 원격에서 삭제된 브랜치 로컬 정리
여러 작업트리(동시 체크아웃)
git worktree add ../repo-main main
git worktree list
git worktree remove ../repo-main
bisect(이진탐색) 버그원인 찾기
git bisect start
git bisect bad # 현재(버그 있음)
git bisect good <commit> # 버그 없던 커밋
# 테스트 후 good/bad 반복…
git bisect reset
최신 main 브랜치 기준으로 시작
git switch main
git pull
git switch -c feature/coupon-issuance
PR 전 커밋 정리
git fetch origin
git rebase -i origin/main # pick/squash 정리
git push --force-with-lease
방금 커밋 메세지 오타 수정
git commit --amend -m "fix: correct typos"
git push --force-with-lease
푸시 전 마지막 커밋 되돌리고 수정 재커밋
git reset --soft HEAD~1
# 파일 수정…
git commit -m "feat: refined implementation"
잘못 푸시된 커밋을 안전하게 되돌리기 (공유 브랜치)
git revert <bad-commit-sha>
git push728x90
'개발 > Git' 카테고리의 다른 글
| 브랜치 만들기, 전환하기 (0) | 2021.09.15 |
|---|---|
| 통합 브랜치, 토픽 브랜치 (0) | 2021.09.14 |
| 브랜치(Branch) (0) | 2021.09.13 |
| 변경 이력 병합(Merge)하기 (0) | 2021.09.11 |
| Push, Clone, Pull (0) | 2021.09.10 |