How to Configure Git to Ignore File Mode Changes

  1. Ignoring file mode changes
  2. Caution
  3. Configuration Levels
    1. --local
    2. --global
    3. --system

There are cases when working on the local development you need to change permissions on various files. Git will think that you made changes on 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 config core.fileMode false

Attaching the --global flag makes it a default for the logged user:

git config --global core.fileMode false
The changes of the global setting will not be added to existing repositories if they locally include the file mode configuration.
The local configuration generated by git init will ignore the global configuration.

Caution

The core.fileMode 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 chmod -R 777 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:

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 git config command writes to a local level by default if no configuration option is passed. The repository of the .git directory has a file (config) 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 (.gitconfig) 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.


Do you find this helpful?

Related articles