How to `git add` non-recursively?

Adding a whole complex directory hierarchy is an unusual thing to do (and certainly not something that happens as part of the usual git development workflow), so git doesn't have a special feature for it. You can always use an external tool to assemble a list of files you want to add and feed that list to git add, e.g. to only add the files in the current directory non-recursively, do

git add $(find . -type f -maxdepth 1)

Alternatively, you could use

git ls-files --others --directory > file-list

to create a list of untracked files in your current directory, and edit it in an editor to remove everything you don't want to add. (Make sure to remove file-list itself.) You can then use

git add $(cat file-list)

to add the files and directories in the edited list. (Directories you leave in will still be added recursively).


A simple alternative is to add a single file in the subdirectory, then you can proceed to add other files as desired.

git add somedir/goodfile
cd somedir
git add anotherfile

If you want to add only the files from the directory without any other subfolders you can do something like:

git add FolderName/\*.* 

Where *.* means every file, from every file type. Folders don't have extensions so they won't pass.

Tags:

Svn

Git

Recursion