This article illustrates how to use git status
to show the working tree status for different needs, like in a short format, not showing the untracked files, etc.
Show the working tree status in normal format
A normal output for a git status
. It will list the files that are to be committed, are not staged and are not tracked separately.
$ git status
On branch main
Your branch is ahead of 'origin/main' by x commits.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: c1.html
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: n1.json
Untracked files:
(use "git add <file>..." to include in what will be committed)
u1.js
u2.js
u3.js
...
Show the working tree status in short format
Below example shows the status in short mode. Each file is listed in one line with the first two colored symbols to indicate the state of the file.
$ git status -s
M c1.html // The first green M indicates the file is to be committed.
M n1.json // The second red M indicates the file has changes not staged.
?? u1.js // The first two red ? indicate the file is untracked.
?? u2.js
?? u3.js
?? ...
Show the working tree status without untracked files
If you have too many untracked files and do not want them to be listed when you check the working tree status, use -uno
option:
$ git status -uno
On branch main
Your branch is ahead of 'origin/main' by x commits.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: c1.html
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: n1.json
Untracked files not listed (use -u option to show untracked files)
-u
optionThe
-u
option decides how to show untracked files. It has three possible values:
no
– Show no untracked files.
normal
– Shows untracked files and directories.
all
– Default value. Also shows individual files in untracked directories.Note the value must be stuck to
-u
, like-uno
, but not-u no
.
Alternately you can create a .gitignore
file to ignore untracked file which takes effect for all commands.