You just removed several tracked files and modified others in your project, but you also created a few brand-new files that you do not want to commit yet. From the repository's root, which single Git command stages the deletions and modifications of tracked files while leaving the new untracked files out of the index?
The --update ( -u ) option tells Git to update the index only where an entry already exists. It therefore stages changes to tracked files-including deletions-without touching any brand-new, untracked paths. Using git add -u (optionally with a pathspec such as ".") achieves exactly what is required.
git add -A or git add --all would also stage the new untracked files because it adds, modifies, and removes entries to match the working tree.
git add . stages modifications to tracked files and adds new files found under the current directory (since Git 2.0, it also stages deletions), so the unwanted files would be included.
git add -i enters interactive mode; it could accomplish the task, but only after extra manual steps, so it does not meet the constraint of a single non-interactive command.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the purpose of the 'git add -u' command?
Open an interactive chat with Bash
How does 'git add -u' differ from 'git add -A'?
Open an interactive chat with Bash
What is the difference between 'git add -u' and 'git add .'?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Automation, Orchestration, and Scripting
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .