loading...

TIL — Git supports a global exclude file

chriis profile image Chris Gregori Originally published at Medium on ・2 min read

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/

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

Posted on by:

Discussion

pic
Editor guide