Skip to content

Instantly share code, notes, and snippets.

@jprivet-dev
Last active March 20, 2023 16:39
Show Gist options
  • Save jprivet-dev/441ca36c4368fe72d52de993aa0dfe47 to your computer and use it in GitHub Desktop.
Save jprivet-dev/441ca36c4368fe72d52de993aa0dfe47 to your computer and use it in GitHub Desktop.
Set up a global .gitignore file to avoid committing IDEs, editors and system files.

Global .gitignore file

Set up a global .gitignore file to avoid committing IDEs, editors and system files.

Step #1 - Create an empty global file

$ touch ~/.gitignore_global

Step #2 - Complete the global file

$ vim ~/.gitignore_global

Copy/Past the following lines:

~/.gitignore_global
# IDEs and editors
.idea/
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
.vimrc
.nvimrc

# Visual Studio Code
.vscode/*
.history/*

# System files
.DS_Store
Thumbs.db
Note
To save in vim, press Esc to enter Command mode, and then type :wq to write and quit the file.

Step #3 - Set up the global file

$ git config --global core.excludesFile '~/.gitignore_global'

Visual Studio Code

If I need to have a more refined strategy for Visual Studio Code, I can, for example, integrate the following block in the project .gitignore file:

.gitignore
# Visual Studio Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/*

Composer & Node

For Composer or Node, it is preferable to configure the .gitignore file of the project, and not the global one, to avoid any other person to end up, at the cloning and at the first installation, with the vendor or node_modules folders marked by Git:

.gitignore
# Composer
vendor/

# Node
node_modules/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment