git add -u, git add -A
git add [<options>] [--] <pathspec>...
git add -u
git add -AStage tracked updates and deletions with -u, or include untracked files as well with -A.
| Parameter | Description |
|---|---|
-u / --update | Stage modifications and removals of tracked files. Untracked files are not added. |
-A / --all | Stage modifications, removals, and untracked files in the repository (subject to pathspec and ignore rules). |
Returns: The index is updated. Follow with git status --porcelain=v1 to inspect XY codes: M and D in the first column after a successful update, and A for a newly staged file.
- The restore --staged step in the script is an unstage, not a working-tree discard.
git init -b main >/dev/null
git config user.name "Practice Author"
git config user.email "[email protected]"
git config commit.gpgsign false
git config color.ui false
mkdir -p .disabled-hooks
git config core.hooksPath ".disabled-hooks"
printf 'a0\n' > a.txt
printf 'b0\n' > b.txt
git add a.txt b.txt
git commit -m "Base" >/dev/null
printf 'a1\n' > a.txt
printf 'b1\n' > b.txt
printf 'c0\n' > c.txt
rm b.txt
echo "before"
git status --porcelain=v1
git add -u
echo "after-update"
git status --porcelain=v1
git restore --staged .
echo "unstaged"
git status --porcelain=v1
git add -A
echo "after-all"
git status --porcelain=v1
Expected output
before
M a.txt
D b.txt
?? c.txt
after-update
M a.txt
D b.txt
?? c.txt
unstaged
M a.txt
D b.txt
?? c.txt
after-all
M a.txt
D b.txt
A c.txt
Related: git status, git restore