DEV Community

Dante De Ruwe
Dante De Ruwe

Posted on • Originally published at dantederuwe.com on

How to create a local gitignore file

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>"

Enter fullscreen mode Exit fullscreen mode

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:

  1. Create a local gitignore file (call it e.g. .local.gitignore)

  2. Add it to the git config as shown above:

  3. 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" &gt; .local.gitignore &amp;&amp; git config --local core.excludesfile "$(pwd)/.local.gitignore"

Enter fullscreen mode Exit fullscreen mode

Powershell (Windows):

Set-Content .local.gitignore ".local.gitignore"; git config --local core.excludesfile "$PWD\.local.gitignore"

Enter fullscreen mode Exit fullscreen mode

Tips

The contents of my local gitignore are mostly as follows:

.local.*
.local/

Enter fullscreen mode Exit fullscreen mode

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)