Sometimes, you want to experiment and tinker with stuff locally without git tracking your files. Think about experimenting with AI agents, local scripts, or even leaving yourself todo notes in every repo.
In stead of carefully avoiding to stage and commit these files, we can let git ignore them without changing the repo's .gitignore!
Additional gitignore files
Did you know you can create additional gitignore files? These can extend your main gitignore file.
You can let git know it should treat an extra gitignore file with:
git config --local core.excludesfile "<my-gitignore-path>"
This way, you can add your experimental files or folders that you're not ready for the world to see, away from the allseeing eye of git 👀
Keeping your gitignore file local
We don't want this gitignore to be added to the repo! So we'll have to set it up to be local.
We're going to do this as follows:
Create a local gitignore file (call it e.g.
.local.gitignore)Add it to the git config as shown above:
Add a reference to the local gitignore file in the local gitignore file itself
🚀 Terminal oneliners for quick setup
Run this in the root folder of your git repository.
Bash (Linux or Git Bash):
echo ".local.gitignore" > .local.gitignore && git config --local core.excludesfile "$(pwd)/.local.gitignore"
Powershell (Windows):
Set-Content .local.gitignore ".local.gitignore"; git config --local core.excludesfile "$PWD\.local.gitignore"
Tips
The contents of my local gitignore are mostly as follows:
.local.*
.local/
This ignores all files starting with .local. (such as .local.gitignore itself!), and also ignores a .local folder where you can keep your super secret files with whatever names you wish.
Top comments (0)