Keep Your Secret Files in a Git Repo (Without Ever Committing Them) 🤫
How to stash personal notes and scratch files inside a Git repo so they never get committed and never vanish when you switch branches.
We’ve all been there. You’re deep in a project and you want to jot something down — a messy investigation note, a scratch SQL query, a TODO that’s just for you. So you drop a notes.md right next to your code.
Then panic sets in. 😱
“Wait… is this going to end up in my next commit? Is my teammate going to see my chaotic brain dump in the PR?”
Good news: there’s a clean, built-in way to keep personal files inside your repo that:
- 🚫 Never get committed
- 👻 Never show up in
git status - 🌿 Never disappear when you switch branches
And the best part? The setting that makes this happen isn’t committed either. Let’s go. 🚀
The obvious idea (and why it’s kinda meh) 🤔
Your first instinct is probably .gitignore. And hey, that works for ignoring files. But there’s a catch:
.gitignore is itself a tracked, committed, shared file.
So if you add my-notes.md to .gitignore, you’re now:
- Making a change that shows up in your
git status(the modified.gitignore). - About to commit that change so it actually takes effect.
- Telling your entire team “hey everyone, please ignore Luthfi’s
my-notes.md” — which is a little weird for something only you have. 😬
.gitignore is perfect for stuff everyone should ignore (node_modules/, .env, build output). It’s the wrong tool for your personal junk.
Meet the hero: .git/info/exclude 🦸
Hidden inside every Git repo is a magical little file:
.git/info/exclude
It works exactly like .gitignore… with two superpowers:
- ✨ It’s local to your machine — it lives inside
.git/, which never gets committed or pushed. - ✨ It applies to the whole repo, across every branch — because
.git/is shared by all your branches.
So it’s the perfect place to say “ignore my personal stuff” without announcing it to the world.
How to use it
Open it up (it starts with some friendly comments) and add a pattern at the bottom:
echo "my-notes.md" >> .git/info/exclude
That’s it. Git now pretends my-notes.md doesn’t exist. It won’t nag you in git status, and it definitely won’t sneak into a commit. 🎉
“But what happens when I switch branches?” 🌿
This is the part people worry about — and it’s actually the coolest bit.
Here’s the rule to remember:
Git only touches files it’s tracking. Files that are untracked and ignored are completely invisible to Git during a
checkout.
So when you run git checkout some-other-branch, Git looks at your ignored personal file, shrugs, and leaves it exactly where it is. 😎
Your notes follow you from branch to branch like a loyal little duckling. 🐥 No copying, no stashing, no “wait which branch did I leave that on?”
Level up: a personal scratch folder 📂
Ignoring files one by one gets old. The pro move is to make a single personal folder and ignore the whole thing. Everything you toss in there is automatically safe.
# 1. Make your secret lair (a hidden dotfolder + a fun name)
mkdir ".luthfis-stuff-📝"
# 2. Tell Git to ignore the whole folder — locally, forever
echo ".luthfis-stuff-📝/" >> .git/info/exclude
Yep, emoji in the folder name totally works. Live a little. 🎨
Now anything you drop in .luthfis-stuff-📝/ — notes, drafts, scratch scripts, screenshots, half-baked ideas — is invisible to Git and survives every branch switch. It’s your own little corner of the repo that nobody else ever sees.
Quick sanity check ✅
Want to confirm Git is really ignoring it? Use check-ignore:
git check-ignore -v ".luthfis-stuff-📝/notes.md"
# .git/info/exclude:7:.luthfis-stuff-📝/ .luthfis-stuff-📝/notes.md
If it prints the rule that’s catching your file, you’re golden. And git status should show… nothing. Beautiful silence. 🤫
The three ways, side by side 📊
| Method | Committed & shared? | Scope | Best for |
|---|---|---|---|
.gitignore | ✅ Yes (tracked) | The repo, for everyone | Stuff the whole team should ignore |
~/.gitignore_global | ❌ No (your machine) | Every repo you touch | OS/editor cruft (.DS_Store, .idea/) |
.git/info/exclude | ❌ No (your machine) | This one repo, all branches | Your personal files in a specific project |
For “I want personal notes in this project and nobody should know,” .git/info/exclude is the sweet spot. 🍯
One tiny gotcha ⚠️
Because .git/info/exclude lives inside .git/, it’s machine-local. If you do a fresh git clone on another laptop, your exclude rules (and any uncommitted scratch files) won’t come along for the ride.
That’s usually exactly what you want for throwaway notes. But if it’s something you’d cry about losing, back it up somewhere real. 💾
Wrap-up 🎁
Next time you want to scribble in a repo without the commitment (pun very much intended 😏):
- Make a personal folder with a name only you’d love.
- Add it to
.git/info/exclude. - Hack away — your stuff stays local, stays put across branches, and never leaks into a PR.
Now go forth and keep your secrets. Git won’t tell. 🤐
Happy hacking! 💚