Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

gitignore

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.

like image 717
Denis Avatar asked Apr 07 '13 12:04

Denis


People also ask

How do I ignore all untracked files?

You can use the git clean command to remove untracked files. The -fd command removes untracked directories and the git clean -fx command removes ignored and non-ignored files. You can remove untracked files using a . gitignore file.

How do I add a folder to a git ignore list?

Repository exclude - For local files that do not need to be shared, you just add the file pattern or directory to the file . git/info/exclude . Theses rules are not committed, so they are not seen by other users. More information is here.

How do I force add an ignored file in git?

The git add command can be used to add ignored files with the -f (force) option.

How do I add only untracked files?

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


2 Answers

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.

like image 157
mrks Avatar answered Sep 30 '22 11:09

mrks


A simpler command to do this is

git ls-files --others --exclude-standard >> .gitignore

You might want to edit the result to replace repeated patterns with wildcards.

like image 12
poolie Avatar answered Sep 30 '22 11:09

poolie