Stage untracked files for commit without staging tracked file changes

Posted by Blair Holloway on Stack Overflow See other posts from Stack Overflow or by Blair Holloway
Published on 2010-06-04T03:51:07Z Indexed on 2010/06/05 9:52 UTC
Read the original article Hit count: 283

Oftentimes, when using git, I find myself in this situation:

  • I have changes to several files, but I only want to commit parts of them.
  • I have added several untracked files, which I want to track and commit.

Solving the first part is easy; I run:

git add -p

Then, I choose which hunks to stage, and which hunks remain in my working tree, but unstaged. However, git's patch mode skips over untracked files.

What I would like to do is something like:

git add --untracked

But no such option appears to exist.

If I have, say, six untracked files, I could stage them using add in interactive mode and the add untracked option, like so:

git add -i
a<CR>
1<CR>
2<CR>
3<CR>
4<CR>
5<CR>
6<CR>
<CR>
q<CR>

I feel like there is, or should be, a quicker way of doing this, though. What am I missing?

© Stack Overflow or respective owner

Related posts about git

Related posts about command-line