Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Only Untracked Files

Tags:

git

git-add

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?

Such as a way to add only the untracked files to the index without identifying them individually?

like image 692
Rob Wilkerson Avatar asked Sep 16 '11 15:09

Rob Wilkerson


People also ask

How do I add all untracked files?

The easiest way to add all files to your Git repository is to use the “git add” command followed by the “-A” option for “all”. In this case, the new (or untracked), deleted and modified files will be added to your Git staging area. We also say that they will be staged.

Does git add * Add untracked files?

So, if you run git add . within a sub directory, it won't add changes to files outside that sub directory. Second, git add . adds both tracked and untracked files.

How do I stash specific untracked files?

In order to stash untracked files, add the “–include-untracked” option to your “git stash” initial command. Alternatively, you can simply use the “-u” which is equivalent to the untracked longer version.

Can I push with untracked files?

yes you can push only the files which you have commited before. you can leave the untracked files and adapt them later.


2 Answers

git ls-files -o --exclude-standard gives untracked files, so you can do something like below ( or add an alias to it):

git add $(git ls-files -o --exclude-standard) 
like image 32
manojlds Avatar answered Oct 29 '22 19:10

manojlds


It's easy with git add -i. Type a (for "add untracked"), then * (for "all"), then q (to quit) and you're done.

To do it with a single command: echo -e "a\n*\nq\n"|git add -i

like image 117
Mat Avatar answered Oct 29 '22 20:10

Mat