tags:

views:

47

answers:

2

Is there a way to use a command like git ls-files to show only untracked files?

The reason I'm asking is because I use the following command to process all deleted files:

git ls-files -d | xargs git rm

I'd like something similar for untracked files:

git some-command --some-options | xargs git add

I was able to find the -o option to git ls-files, but this isn't what I want because it also shows ignored files. I was also able to come up with the following long and ugly command:

git status --porcelain | grep '^??' | cut -c4- | xargs git add

It seems like there's got to be a better command I can use here. And if there isn't, how do I create custom git commands?

+3  A: 

If you just want to remove untracked files, do this:

git clean -df

add x to that if you want to also include specifically ignored files. I use git clean -dfx a lot throughout the day.

You can create custom git by just writing a script called git-whatever and having it in your path.

Dustin
It's much more common that I want to *add* all untracked files (for example, after I move some things around). In any case, thanks for the tip about custom commands. Where is that mechanism documented?
jnylen
Just do `git add -A` or `git add -u` (depending on which makes more sense to you)
Dustin
+1  A: 

To list untracked files try:

git ls-files --other --exclude-standard

Nice alias for adding untracked files:

au = !git add $(git ls-files -o --exclude-standard)
takeshin
Perfect! What does the `!` mean at the beginning of the alias line, or where is that documented?
jnylen
@jnylen: `!` runs bash command so you could use `$(...)`
takeshin
git help config
Dustin