Checking Git Status (git status)
What Will We Learn?
What is git status, what it shows and the short version of it.
How git status Works?
git status examines your working directory, staging area and the repository and provides a summary of your repository state.
What git status reveals?
git status reveals current state of the repository:
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: README.md
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: file
Untracked files:
(use "git add <file>..." to include in what will be committed)
app.pyBy examining the output of git status, we can infer that it shows:
- which branch you are currently in
- which files will be included in the next commit
- which files are modified but not staged yet
- which files are yet to be tracked by Git, etc.
Note
The output is not always the same. For eg: if you nave no untracked files, Git won’t show it.
When to use git status?
While working on Git repository, you often will find yourself using this git status before or after commiting changes to see the current repository status, what changes are and are not going to be included, etc. The above output is generally of before committing changes although it may appear after committing too. A different kind of output can be seen sometimes as such:
On branch master
Your branch is ahead of 'origin/master' by 3 commits.
(use "git push" to publish your local commits)
Untracked files:
(use "git add <file>..." to include in what will be committed)
content/git/git-basics/git-status.md
nothing added to commit but untracked files present (use "git add" to track)It shows that your local repository is 3 committs ahead from remote repo. To sync, it suggests to just fire git push.
git status Short Version
git status -s gives you short output. For eg, if you use this short version for this example, it produces:
?? content/git/git-basics/git-status.md?? simply means untracked file.
For first output here, the output will be:
M README.md
M file
?? app.pyM is staged and modified, .M is not staged but modified (space at the beginning says that, leading space is not being rendered properly so . is used to denote a space) and ?? is untracked.
The output of git status -s (or git status --short) has the format:
XY path- X = status of the staging area (index)
- Y = status of the working tree
Status codes
| Code | Meaning |
|---|---|
(space) | No change in that area. |
M | Modified. |
A | Added (new file staged). |
D | Deleted. |
R | Renamed. |
C | Copied. |
U | Updated but unmerged (merge conflict). |
? | Untracked file. |
! | Ignored file (only shown with git status --ignored). |