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.js

Stage 후 상태 확인

$ 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”

원인:

  1. 파일을 저장하지 않음
  2. .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

관련 명령어

더 알아보기