0

I've added few files in .gitignore but doing git add . first time and committing, pushing pushes even files which should have been ignored

#Sensitive Data
aws-exports.js
aws-exports-dev.js
aws-exports-main.js
.env

I saw these files getting committed to GH repo

vikramvi
  • 3,312
  • 10
  • 45
  • 68

1 Answers1

0

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250