Home > Software engineering >  What does a gitignore global config do exactly?
What does a gitignore global config do exactly?

Time:10-25

I have been reading online, but still a bit confused. After running the below configuration for my local set up. Will I ever need to create a gitignore for any projects again in the future?

git config --global core.excludesfile %USERPROFILE%\.gitignore

And is there a way to set up a dynamic config where the text file would be updated with current changes ?

CodePudding user response:

The core.excludesfile works like a .gitignore file, but it has a different purpose. A .gitignore file is project specific and it's designed to contain various things that the project wants to ignore, often because they're build products. For example, a project written in C will probably want to ignore the built binary or shared library, plus any files matching *.o or *.obj. These are things that every user of your project will want to ignore.

The core.excludesfile is designed for patterns you personally would like to ignore. For example, if you use Vim, you'll probably want to ignore swap files so that you don't accidentally check them in. Since people use many different editors, it doesn't make sense to ignore every different type of editor file in every project, so this is an opportunity to ignore things like editor backup files, tags files, and similar stuff.

There's also a third set of configuration, which is in .git/info/exclude. Since it's in the .git directory, it's specific to the project, but it's not shared. It's for cases when you need to modify the project's include patterns for your local system, but in a way that isn't relevant to others. For example, I have a project where I have a dotfile to help my editor find the real root of the project, and this file is specific to my configuration.

So to answer your question, you should still write .gitignore files for your projects if they have build products or other project-specific data to ignore. There is no way to dynamically or automatically configure the patterns, but usually you should not need to do this.

Note that in your case, you need to write the pattern as ~/.gitignore. Git does not expand environment variables in the config file, but usually ~, which represents the home directory, will match the value of the USERPROFILE environment variable.

  • Related