Picture of Julien Wittouck

Julien WITTOUCK

freelance solution & software architect πŸ— - containers πŸ‹ & linux 🐧 πŸ’™ - teacher & trainer πŸŽ“ @ univ-lille.fr - πŸŽ™οΈ speaker

Home

Configure a Global Gitignore πŸ™ˆ

Published Jun 01, 2020 - Updated Jun 17, 2022

197 words, 1 minutes to read

This short articles shows how to setup a global .gitignore file, to exclude files or directories for all your git repositories.

This is very useful for editor files or .env file, and prevents accidental commits. I also added common directories for Java and NodeJS related developments (target/ and node_modules), and IntelliJ IDEA files (*.iml and .idea/)

Thus said, you should also always setup a .gitignore file in your projets, as the global file only work for you, and will not be shared with the code of your project.

create the .gitignore file

On Linux systems, the default location for a global .gitignore file is ~/.config/git/ignore.

Create this file if it doesn’t exist, and put your content in it:

# create the directory if it doesn't exists
$ mkdir -p ~/.config/git

# create the global ignore file
$ cat <<EXCL >> ~/.config/git/ignore
# global gitignore file

# idea settings
.idea/
*.iml

# java
target/

# direnv
.envrc
.env
EXCL

And you are done!