DEV Community

Chris Gregori
Chris Gregori

Posted on • Originally published at Medium on

2 2

TIL — Git supports a global exclude file

TIL — Git supports a global exclude file

A tiny tip that might help a lot of you

I don’t really know why I didn’t think this was a thing until today but I was having some issues with elixir_ls (a VSCode plugin for Elixir development) plaguing my git repository up and my projects .gitignore file was seemingly ignoring the generated files.

There also seem to be some Github issues talking about the same thing so I wasn’t alone in my folly.

Solution

Your git installation can have a global .gitignore file! I’ve been programming for 5 years and had no idea — I’m not really sure why I didn’t consider it in the past.

To add a global **.gitignore file:**

git config --global core.excludesfile ~/.gitignore

To edit a global .gitignore file:

sudo vim ~/.gitignore (or an editor of your choice)

Here are the contents of mine — I took the liberty of adding some other common files I want to ignore in there too:

.DS\_Store
node\_modules/
.elixir\_ls/
Enter fullscreen mode Exit fullscreen mode

Optional extra

Some of you might do this then find that your .gitignore hasn’t taken effect — the following commands will fix this:

git add [uncommitted changes you want to keep] && git commit
git rm -r --cached .
git add .
git commit -m "fixed untracked files"
Enter fullscreen mode Exit fullscreen mode

Hope this helped! It cleared up my VScode woes.

Enjoyed my ramblings? Follow me on twitter to hear more of my development tales or keep up with my side projects on my personal site. 💻

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay