DEV Community

Cover image for why isn't .gitignore working?πŸ€”
Richard
Richard

Posted on

why isn't .gitignore working?πŸ€”

T'was the night before bootcamp, and all through the street,
not a creature was stirring (but the smoke detector beeped)beep
A lone coder sat, by his laptop with care
Put a file in .gitignore, but the file was still there!beep

git rm -rf --cached .
Enter fullscreen mode Exit fullscreen mode

I realized that I had left a file sitting in my repo that had an API key in it. Don't want that sitting around where some crawling bot
Image description
can find it, do I?

So I added the file to my .gitignore file. And it didn't work.

And I spent like half an hour trying to figure out if I had the .gitignore in the wrong place, or if I was somehow leaving out a / or spelling the /path/wrong/somehow.js..

I wasn't. You have to run the cache-clearing command above sometimes to clear files from the cache, before you do a git add and commit and push up to GitHub. Truthfully I should explain it better but it's almost 2am and I need to go to sleep. Google it first so you don't blow anything up.

I also used this command:

git checkout --orphan newbranch
Enter fullscreen mode Exit fullscreen mode

To create a brand new branch with no commit history, so I didn't push to GitHub my current branch for main which successfully added the errant file to .gitignore but still had the file as part of a long string of previous commits.

beep πŸ˜†

Top comments (0)