How to find if files are already tracked ? I'm on Mac OS
As seen here:
git ls-files --error-unmatch <file name>
echo $?
- If this prints 0, there was no error, meaning the file was tracked by Git. - If it prints 1, then the file was not tracked by Git.
Also:
git check-ignore -v -- aFile_that_should_be_ignored
If it prints nothing while you know if should be ignored, it means it is already tracked:
git rm --cached -- aFile_that_should_be_ignored
git check-ignore -v -- aFile_that_should_be_ignored
This time, your .gitignore
rule should be displayed.
Note that you can create a GitHub repository from command-line (locally), with a .gitignore
template (from github/gitignore
), using gh repo create --gitignore=xxx
(PR 3746).
Then you would clone your GitHub repository, and start working in it: any file that should be ignored would be, since none would have yet been tracked in that new local clone.