git status
한 줄 요약
현재 저장소의 상태를 확인 (변경된 파일, Stage 상태 등)
기본 사용법
git status현재 Repository의 상태를 보여줍니다.
주요 옵션
| 옵션 | 설명 | 예시 |
|---|---|---|
| (없음) | 상세한 상태 표시 | git status |
-s / --short | 간략한 상태 표시 | git status -s |
-b / --branch | 브랜치 정보 포함 | git status -sb |
출력 이해하기
기본 출력
$ git status
On branch main # 현재 브랜치
Your branch is up to date with 'origin/main'.
Changes to be committed: # Stage에 있음 (초록색)
(use "git restore --staged <file>..." to unstage)
modified: app.js
new file: utils.js
Changes not staged for commit: # 수정했지만 Stage 아님 (빨간색)
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: style.css
Untracked files: # 새 파일 (추적 안 함)
(use "git add <file>..." to include in what will be committed)
newfile.txt간략한 출력 (-s)
$ git status -s
M app.js # Stage에 있는 수정
M style.css # Stage에 없는 수정
A utils.js # Stage에 있는 새 파일
?? newfile.txt # Untracked 파일| 기호 | 위치 | 의미 |
|---|---|---|
M | 첫 번째 열 | Staged 수정 |
M | 두 번째 열 | Unstaged 수정 |
A | 첫 번째 열 | Staged 새 파일 |
D | - | 삭제됨 |
R | - | 이름 변경 |
?? | - | Untracked |
깨끗한 상태
$ git status
On branch main
nothing to commit, working tree clean모든 변경사항이 커밋되어 있습니다.
상태별 파일 흐름
┌─────────────────────────────────────────────────────────────┐
│ │
│ Untracked ──git add──▶ Staged ──git commit──▶ Committed │
│ │ ▲ │
│ │ │ │
│ └────────────────────┘ │
│ │
│ Modified ───git add───▶ Staged ──git commit──▶ Committed │
│ │ │ │
│ │ git restore │ git restore --staged │
│ ◀────────────────────┴────────────────────── │
│ │
└─────────────────────────────────────────────────────────────┘
실제 예제
작업 전 상태 확인
# 작업 시작 전 현재 상태 확인
$ git status
On branch main
nothing to commit, working tree clean
# 파일 수정
$ echo "new code" >> app.js
# 상태 다시 확인
$ git status
Changes not staged for commit:
modified: app.jsStage 후 상태 확인
$ git add app.js
$ git status
Changes to be committed:
modified: app.js브랜치 상태 확인
$ git status -sb
## main...origin/main
M app.js원격 저장소와의 차이
# 로컬이 앞서 있을 때
$ git status
Your branch is ahead of 'origin/main' by 2 commits.
(use "git push" to publish your local commits)
# 원격이 앞서 있을 때
$ git status
Your branch is behind 'origin/main' by 3 commits.
(use "git pull" to update your local branch)
# 갈라졌을 때
$ git status
Your branch and 'origin/main' have diverged,
and have 2 and 3 different commits each, respectively.자주 하는 실수
수정했는데 “nothing to commit”
원인:
- 파일을 저장하지 않음
.gitignore에 포함된 파일
확인:
# 파일 저장 후 다시 확인
git status
# .gitignore 확인
cat .gitignore많은 파일이 Untracked로 표시됨
원인: .gitignore가 없거나 불완전함
해결:
# .gitignore 생성
echo "node_modules/" >> .gitignore
echo ".env" >> .gitignore유용한 별칭 설정
# 짧은 상태 확인
git config --global alias.st "status -s"
git config --global alias.ss "status -sb"
# 사용
git st
git ss관련 명령어
- git add - Stage에 추가
- git commit - 변경사항 커밋
- git diff - 변경 내용 자세히 보기
- git restore - 변경사항 되돌리기
더 알아보기
- Stage와 Working Directory - Git의 세 영역
- Commit - 커밋의 개념