TIL — Git supports a global exclude file

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.

What is a .gitignore file?

In case you didn’t know, a .gitignore file is a file that sits at the top level of your project directory to tell git which file paths to ignore when it performs its magic. You wouldn’t want to commit your project dependencies or files specific only to your machine when contributing to some code after all.


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:


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"

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. 💻



Senior Software Engineer @Multiverse — ex @Skyscanner & @NETAPORTER

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Chris Gregori

Chris Gregori

Senior Software Engineer @Multiverse — ex @Skyscanner & @NETAPORTER