git status
- Version
- 2.51
- Review
- Draft
Summary#
git status reports staged, unstaged and untracked paths. In short and porcelain output, the first status column describes the index and the second the working tree; ?? marks an untracked path. Unmerged paths use the two columns to describe each side of the conflict.
Syntax#
git status
git status --short --branch
git status --porcelain=v1 -z
git status --untracked-files=all
Example#
(
set -eu
scratch=$(mktemp -d "${TMPDIR:-/tmp}/devlookup-git.XXXXXX")
trap 'rm -rf -- "$scratch"' EXIT
unset GIT_CONFIG_GLOBAL $(git rev-parse --local-env-vars)
export GIT_CONFIG_NOSYSTEM=1 GIT_TEMPLATE_DIR= LC_ALL=C
export HOME="$scratch" XDG_CONFIG_HOME="$scratch" GIT_ATTR_NOSYSTEM=1
export GIT_PAGER=cat GIT_EDITOR=true
mkdir "$scratch/work"
cd "$scratch/work"
git init -q -b trunk
git config user.name "Reference Example"
git config user.email example@example.invalid
git config core.excludesFile /dev/null
printf 'v1\n' > config.txt
printf 'guide\n' > guide.txt
git add config.txt guide.txt
git commit -qm "Add files"
printf 'v2\n' > config.txt
git add config.txt
printf 'v3\n' > config.txt
git mv guide.txt manual.txt
mkdir drafts
printf 'idea\n' > drafts/idea.txt
git status --porcelain=v1 --branch
echo "all untracked files:"
git status --porcelain=v1 --untracked-files=all -- drafts
)
Expected output#
## trunk
MM config.txt
R guide.txt -> manual.txt
?? drafts/
all untracked files:
?? drafts/idea.txt
Common mistakes#
Do not parse the default long output, which can change, or rely on --short paths, which are relative to the current directory. For scripts, use --porcelain=v1 -z to read NUL-delimited names. In rename entries, this mode gives the destination first, followed by the source. By default an untracked directory appears as one entry, not as its files.
Version applicability#
Git 2.11 added porcelain format selection. --porcelain=v1 names the original format, which older Git releases select with --porcelain.
The complete example requires Git 2.28 or later for git init -b.
Sources#
- Attribution
- DevLookup contributors
- License
- CC-BY-4.0