DEV Community

Discussion on: Did you just say you want to 'git add' all those files except 1?

Collapse
 
loumarven profile image
loumarven

Hey there,

Came across this post as I was searching for a solution to the same problem.
Saw this in StackOverflow:

Now git supports exclude certain paths and files by pathspec magic :(exclude) and its short form :!. So you can easily achieve it as the following command.

git add --all -- :!main/dontcheckmein.txt
git add -- . :!main/dontcheckmein.txt

Actually you can specify more:

git add --all -- :!path/to/file1 :!path/to/file2 :!path/to/folder1/*

The -- option separates the add command from the list of files, so the files won't be mistaken as command-line options. In the case above, all files in the current directory (.), except excludedfile.
I've yet to find a documentation for the syntax of the exclusion of files, but I've been using the command and has been working for me (my Git version is 2.20).