keyboard-shortcut
d

global git ignore 🫣

2min read

an image

The problem

Often you will see some weird entries in a .gitignore file. Some of these are justified, but quite often there are many entries that shouldn't be in your code base. The .gitignore file should be specific and scoped to your library/application (not anything else). Quite often you will see entries like the following:

### JetBrains ###
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

### SublimeText ###
# Bit of a blast from that past...
# Cache files for Sublime Text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache

### Vim ###
# Swap
[._]*.s[a-v][a-z]
!*.svg  # comment out if you don't need vector files
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]

# Session
Session.vim
Sessionx.vim

These entries are not relevant to the code base. They are all relevant to the tools that a particular developer uses. 🛠

Global .gitignore file

To avoid tracking these files in your project, but not pollute the .gitignore file with lots of custom entries you can configure a global .gitignore file. This will apply to all projects, regardless of their location (meaning the project can only include relevant entries).

Firstly, create the file somewhere sensible. Given this is a global file, I store mine at my user root path:

touch ~/.gitignore

You can then populate it with whatever you need!

echo ".DS_Store" >> ~/.gitignore

You can then configure git to adopt this global gitignore file:

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

Job done! ✅