How to Configure Git to Ignore File Mode Changes

John Wachira Feb 02, 2024
How to Configure Git to Ignore File Mode Changes

This article discusses the step necessary to configure Git to ignore file changes (chmod). If you change permissions on a file that Git was tracking, the system will register a change in the file.

Here are the steps to follow to make Git ignore file mode changes.

Ignore File Mode Changes in Git

Run the command below within your repository to instruct Git to ignore file mode changes.

$ git config core.fileMode false

You can make it your default by adding the --global flag, as shown below.

$ git config --global core.fileMode false

The above practice is not always recommended since it exclusively deals with the executable part of mode and not the read/write parts.

In most cases, you will use the core.fileMode setting because you did a simple chmod -R 777 to make your files executable. Remember that most files are not executable for security reasons.

The best method to deal with this issue involves managing the folder and file permission separately, as shown below.

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

This reduces the chance of using the core.fileMode settings in Git.

In a nutshell, most files are not executable for security reasons. Take caution when using the core.fileMode settings.

We have also covered a better approach that reduces your odds of using the core.fileMode settings.

Author: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.

LinkedIn