chmod
file permissions
Git
terminal commands
Linux basics

How to add chmod permissions to file in Git?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

When people ask how to add chmod permissions to a file in Git, the precise answer is that Git does not track all Unix permission bits. For normal files, Git effectively tracks one permission-related state: whether the file is executable.

What Git Records

On Unix-like systems, the filesystem may store read, write, and execute bits for owner, group, and others. Git does not preserve that entire permission matrix in commits.

For regular files, Git stores either:

  • non-executable, mode 100644
  • executable, mode 100755

That means you can use Git to record that a script should be runnable, but you cannot use it to version-control details such as 640 versus 644 for a normal file.

The Normal Way To Add Execute Permission

If you want Git to remember that a shell script is executable, change the file mode in your working tree and stage the change.

bash
chmod +x deploy.sh
git add deploy.sh
git diff --cached --summary

The diff summary should show a mode change similar to this:

bash
mode change 100644 => 100755 deploy.sh

Now commit it:

bash
git commit -m "Make deploy script executable"

Anyone who clones the repository onto a filesystem that supports Unix execute bits should receive the file as executable.

Use git update-index If Needed

Sometimes you want to record the executable bit directly through Git, especially in environments where chmod is awkward or where mode changes are not detected automatically.

bash
git update-index --chmod=+x deploy.sh
git diff --cached --summary

To remove execute permission:

bash
git update-index --chmod=-x deploy.sh

This command only affects the executable flag that Git knows how to store.

Verify Your Repository Settings

A common source of confusion is core.fileMode. If it is disabled, Git may ignore executable-bit changes in the working tree.

Check the setting:

bash
git config core.fileMode

If the repository or global configuration prints false, Git may not notice mode changes from chmod. In that case either enable it:

bash
git config core.fileMode true

or use git update-index --chmod=+x explicitly.

This issue shows up often on shared folders, Windows filesystems, or containers mounted from hosts that do not preserve Unix permissions cleanly.

What Happens On Windows

Windows does not use the same executable bit model as Linux or macOS. Git can still record the executable flag in the repository, but your local filesystem may not express it the same way.

That means a script committed as executable may still need to be run with an explicit interpreter on Windows, such as:

bash
bash deploy.sh

The important point is that Git history can still carry the 100755 mode so Unix users get the correct behavior after checkout.

A Practical Example

Suppose your project includes a helper script that fails in CI with Permission denied.

The fix is usually:

bash
chmod +x scripts/build.sh
git add scripts/build.sh
git commit -m "Mark build helper as executable"

CI systems that check out the repository onto Linux runners will then be able to execute the script directly:

bash
./scripts/build.sh

That is the main real-world case where permission handling in Git matters.

Common Pitfalls

The most common mistake is expecting Git to track all chmod changes. It does not. For regular files, only the executable bit matters.

Another pitfall is running chmod +x and forgetting to stage the file. Until you add the change to the index, the mode update is not part of the next commit.

People also get confused by core.fileMode=false. In that configuration, chmod may appear to do nothing from Git's perspective.

Finally, do not assume that Windows will behave like Linux. The repository can store the executable flag, but the local platform still controls how scripts are launched.

Summary

  • Git tracks the executable bit for regular files, not the full Unix permission set.
  • Use chmod +x file and git add file to record an executable script.
  • 'git update-index --chmod=+x file is a direct Git-level alternative.'
  • Check core.fileMode if Git is not noticing permission changes.
  • The most important practical use case is fixing Permission denied for scripts in Unix-like environments.

Course illustration
Course illustration

All Rights Reserved.