DEV Community

Cover image for why isn't .gitignore working?🤔
Richard
Richard

Posted on

1 1

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 😆

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more