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.
If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.
Just add a pattern to .gitignore
.*
!/.gitignore
Edit: Added the .gitignore
file itself (matters if it is not yet commited).
.gitignore will only effect files that haven't been 'added' already.
To make new .gitignore entries affect all files
git commit -a -m "Pre .gitignore changes"
git rm -r --cached .
git add .
git commit -a -m "Post .gitignore changes"
git status
should output "nothing to commit (working directory clean)"
`In .git/info/exclude
, add this line:
.*
This will make ignoring all hidden/dot files recursively the default for every repository on the machine. A separate .gitignore
file for every repo is not needed this way.
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