Git advisory regarding ignored files can be turned on or off

Alonso Del Arte
2 min readOct 29, 2024

--

Photo by Christina @ wocintechchat.com on Unsplash

Working on Git as long as I have, you start to notice that different versions of Git behave slightly different. If you really want Git on each of your devices to behave the same way with regard to advisory messages and other configurable details, you might have to make sure it’s the same version on every device and the configuration file is exactly the same.

For example, when using the Git Add command with a pattern that might match some ignored files, Git on my Windows 10 computer doesn’t say anything about matching those ignored files, but Git on my Mac does.

I prefer to use a specific pattern for the Git Add command even when I can use the wildcard to match all changed files.

Working on a Java project using Apache NetBeans for macOS today, I gave Git the command

al@MacBook-Pro-155 CurrencyDemo % git add **/currency/LocalesInfoGatherer**

even though I could just as easily have used

al@MacBook-Pro-155 CurrencyDemo % git add .

Git responded

The following paths are ignored by one of your .gitignore files:
build
hint: Use -f if you really want to add them.
hint: Turn this message off by running
hint: "git config advice.addIgnoredFile false"
al@MacBook-Pro-155 CurrencyDemo %

As I have NetBeans configured to compile on save, it created LocalesInfoGatherer.class in the build/classes/currency folder, and LocalesInfoGathererNGTest.class in the build/test/classes/currency folder.

Those Java bytecode files should not be checked into version control. It would be too easy for compiled files to get out of sync with the source files, plus there’s also the issue of trust of whether or not compiled files from version control are deliberately not derived from the source files.

Git is doing the right thing not automatically adding files that are on the Git Ignore on any of my devices with Git installed. So I’m not going to run Git Add with the Force flag.

I don’t remember ever running the Git Configuration command on any of the devices I have Git installed on. And I’m not inclined to run the suggestion for a configuration to turn off the advisory message on my Mac, nor will I run a configuration command to turn those advisory messages on for my Windows 10 computer.

Still, it’s a good idea to pay attention to such messages, and only turn them off if you’re absolutely sure you understand the implications of the hints.

--

--

Alonso Del Arte
Alonso Del Arte

Written by Alonso Del Arte

is a Java and Scala developer from Detroit, Michigan. AWS Cloud Practitioner Foundational certified

No responses yet