Sometimes, it makes sense to forbid git commit when there are untracked files, because you should add them either to files to commit or gitignore. And an option like -f to force this commit is also necessary. So is there any option/plugin/etc to do that? Thank you very much.
Sometimes, it makes sense to forbid git commit when there are untracked files, because
Share
You can add a pre-commit hook that exits with a non-zero value if you find untracked files (you could examine the output of
git status --porcelain -uto determine their presence–look for lines beginning with “?”). Then you can override the commit verification withgit commit --no-verifyif you don’t care about the untracked files.Edit: Thanks to @Jefromi; I don’t have my git environment at hand to test. He also notes that this command should identify the presence of untraced files:
git status -u | grep '^# Untracked files:$'.