W3docs

How to Configure Git to Ignore File Mode Changes

Sometimes, working on local development there is a need to change permissions on various files. The tutorial will show how to ignore the File Mode changes.

During local development, you may need to change permissions on various files. Git will think that you made changes to the file if it was being tracked. Let's see how to ignore these changes.

Ignoring file mode changes

Run the following within the repository to ignore the changes:

git ignore the changes

git config core.fileMode false

Attaching the <kbd class="highlighted">--global</kbd> flag makes it a default for the logged user:

git ignore the changes default for the logged user

git config --global core.fileMode false
Info

The global setting will not apply to existing repositories if they already have a local file mode configuration.

Warning

Local configuration takes precedence over global configuration.

Caution

The <kbd class="highlighted">core.fileMode</kbd> is not recommended practice. It covers only the executable bit of mode not the read/write bits. There are cases when you use this setting just because you did <kbd class="highlighted">chmod -R 777</kbd> to make your files executable. But you should remember that most files shouldn’t be executable for many security reasons.

The appropriate way to solve this kind of problem is to manage the folder and file permission separately by running the following:

Make folders traversable and read/write and make files read/write

find . -type d -exec chmod a+rwx {} \; # Make folders traversable and read/write
find . -type f -exec chmod a+rw {} \;  # Make files read/write

Configuration Levels

The git config command accepts arguments to define on which configuration level to operate. When searching for a configuration value, Git prioritizes the following orders:

--local

The <kbd class="highlighted">git config</kbd> command writes to a local level by default if no configuration option is passed. The repository of the <kbd class="highlighted">.git</kbd> directory has a file (<kbd class="highlighted">config</kbd>) which stores the local configuration values.

--global

The application of this level includes the operating system user. Global configuration values are found in a file (<kbd class="highlighted">.gitconfig</kbd>) located in a user's home directory.

--system

This configuration includes all users on an operating system and all repositories. The System-level configuration file is placed in the git config file of the system root path.