Denis Denis - 3 months ago 9
Git Question

how to add all currently untracked files/folders to git ignore?

I initialized the

git
repository and made a first commit.
Now, in this directory I run
./configure
and
./make all
so that it populates a lot of extra files/folders don't want to track.

What I would like to do, is to add all those untracked files once and for all to my gitignore. Is there any simple way to do it?

I can get rid of some unnecessary files like
*.o
or
*.mod
by specifying appropriate lines in .gitignore, but this does not solve the problem.

Answer

Try this:

git status -s | grep -e "^\?\?" | cut -c 4- >> .gitignore

Explanation: git status -s gives you a short version of the status, without headers. The grep takes only lines that start with ??, i.e. untracked files, the cut removes the ??, and the rest adds it to the .gitignore file.

Comments