To make Git ignore file mode (permission) changes (e.g., chmod
modifications), you can configure Git to disregard executable bit changes. Here’s how to do it:
Step 1: Configure Git to Ignore File Mode Changes
Set the core.fileMode
setting to false
in your Git configuration.
For a Single Repository (Local Config):
git config core.fileMode false
For All Repositories (Global Config):
git config --global core.fileMode false
Step 2: Verify the Setting
Check if the setting is applied correctly:
git config --get core.fileMode
# Output: false (if set correctly)
How It Works
- When
core.fileMode
isfalse
, Git will ignore changes to file permissions (e.g.,755
→644
). - This setting does not affect existing tracked files until their content changes. To refresh the index for existing files, run:
git reset --hard HEAD
Example Workflow
- Before Configuration:
chmod +x script.sh # Make a file executable
git status # Shows "modified: script.sh"
- After Configuration:
git config core.fileMode false
chmod +x script.sh # Permission change
git status # No changes detected
Notes
- Windows Users: Git for Windows automatically sets
core.fileMode
tofalse
because file modes are not natively tracked. - Unix/Linux/macOS:
core.fileMode
istrue
by default. - Exception: To stage a permission change for a specific file, temporarily re-enable
core.fileMode
:
git -c core.fileMode=true add script.sh
Troubleshooting
If files still show mode changes after configuration:
- Refresh the Git Index:
git update-index --really-refresh
- Check for Overrides:
Ensure no other Git config files (e.g.,.git/config
or~/.gitconfig
) override the setting.
By disabling core.fileMode
, you ensure Git focuses on content changes, not permissions.