Hi, I am Mofei!
...

Set Up a Global .gitignore File

Keep your project .gitignore clean by configuring a global ignore file for system and editor-specific clutter.

January 4, 2021 at 10:46 AM

When reviewing code, We may see commits like this in the .gitignore file:


composer.lock
package.lock
+ .vscode

Among them, .vscode is the configuration file of vscode. If everyone puts their own environment/editor configuration in .gitignore, the .gitignore file will be very long and difficult to maintain. To keep your project clean and tidy, we can use the global .gitignore

global .gitignore

  1. Create a new global .gitignore file in home path, which is usually a good choice for:
touch ~/.gitignore
  1. Edit the .gitignore file and put the content that needs to be excluded globally, such as:
.cache
.vscode
.DS_Store

Typically, you'll want to exclude the operating system's temporary files (like .DS_Store in Mac) and your editor's temporary configuration files (like Vscode's .vscode) files.

  1. Run the following command to make your global configuration take effect:
git config --global core.excludesfile ~/.gitignore

In this way, we don't have to add these duplicate files to all projects in the future!

Subscribe by email

Writing about Finland, life, and code. The next post goes straight to your inbox, without the noise.

More Articles

I put a lot of thought into this post—would love to hear your thoughts!

Hi, I am Mofei

Coding, and living with intention.

Subscribe
© 2012–2026 Mofei·Privacy·Terms
Life compiled in code
Set Up a Global .gitignore File | Hi, I am Mofei!