One of the commands I find incredibly useful in Git is git add -u
to throw everything but untracked files into the index. Is there an inverse of that? In the last few months, I've often found myself in a position where I've interactively added some updates to the index and I want to add all of the untracked files to that index before I commit.
Is there a way to add only the untracked files to the index without identifying them individually? I don't see anything obvious in the help docs, but maybe I'm missing it?
Thanks.
git ls-files
lists the files in the current directory. If you want to list untracked files from anywhere in the tree, this might work better:To add all untracked files in the tree:
It's easy with
git add -i
. Typea
(for "add untracked"), then*
(for "all"), thenq
(to quit) and you're done.To do it with a single command:
echo -e "a\n*\nq\n"|git add -i
git ls-files -o --exclude-standard
gives untracked files, so you can do something like below ( or add an alias to it):To add all untracked files git command is
Also if you want to get more details about various available options , you can type command
instead of first command , with this you will get more options including option to add all untracked files as shown below :
Not exactly what you're looking for, but I've found this quite helpful:
Will add all files to the index, but without their content. Files that were untracked now behave as if they were tracked. Their content will be displayed in
git diff
, and you can add then interactively withgit add -p
.People have suggested piping the output of
git ls-files
togit add
but this is going to fail in cases where there are filenames containing white space or glob characters such as*
.The safe way would be to use:
where
-z
tells git to use\0
line terminators and-0
tells xargs the same. The only disadvantage of this approach is that the-0
option is non-standard, so only some versions ofxargs
support it.