Byte Ebi's Logo

Byte Ebi 🍀

A Bit everyday A Byte every week

[Git Tutorial] Configuring Global gitignore Locally

Stop uploading editor configuration files! I really don't want to know what editor you use.

Ray

Do you include automatically generated editor configuration files in your .gitignore while developing a project?
Why add your personal environment settings to the project?

For instance, if you’re using PhpStorm, it generates a .idea folder: What is the .idea folder?
If you’re on an Apple system, you’ll encounter .DS_Store: wiki .DS_Store
During personal development, it’s convenient to add these to .gitignore for a clean and tidy workspace.
But when you’re part of a team project, this approach becomes impractical.

Typically, .gitignore is for excluding project settings, keys, rendered content, etc., from version control.
Therefore, including idea and .DS_Store in gitignore isn’t reasonable, as not everyone needs to ignore these files.

Actually, we can configure this locally in the git settings because your machine won’t suddenly switch from Mac to Windows.
Excluding specific files or paths from version control in the local environment sounds much more reasonable.

Operation Steps

1 Create a Global gitignore Configuration File

The filename can be anything; use the terminal to execute the command:

touch .gitignore_global

2 Add Files to be Ignored

Similar to .gitignore, you can manually open the file for editing or execute:

echo /.idea >> .gitignore_global

3 Add the Configuration File to .gitconfig

You can manually edit or use the following command:

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

4 Check if the Configuration is Successful

The simplest way is to open the project and delete the corresponding settings in .gitignore.
However, let’s review what we’ve just configured.
You can use commands to view or directly open the file.
Using commands seems more sophisticated, so let’s give it a try:

vim .gitignore_global

Here, you can see the list of files we want to ignore in the configuration file.
Some might have been added during the initialization of Git. Just ensure our added content is written in the file:

*~
.DS_Store
/.idea

Next, check if the git configuration file has been set:

vim .gitconfig

You can see in the excluded file settings, it’s specified to the ignore list configuration file we just created:

[core]
    excludesfile = {path to .gitignore_global}

By doing this, we’ve completed the “Local Global gitignore Configuration” task. Reference: git gitignore

Recent Posts

Categories

Tags