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.
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.
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.
The git add command can be used to add ignored files with the -f (force) option.
It's easy with git add -i . Type a (for "add untracked"), then * (for "all"), then q (to quit) and you're done.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With