Change/update permissions on a tracked file in Git¶
Overview¶
In Git, file permissions are tracked only for the executable bit — meaning Git records whether a file is executable (+x) or non-executable. This exists to ensure that scripts and binaries retain their runnable status when cloned, checked out, or pulled across different systems.
Git does not track read/write permissions, which are specific to the operating system.
Git ignores other file permission details (like read/write bits) to maintain cross-platform consistency — since permission systems differ across operating systems.
Common Use Cases:
- ✅ Making a script executable (e.g.,
.sh,.py,.plfiles). - 🧩 Ensuring consistent file behavior across developers and CI/CD environments.
- 🔁 Committing permission-only changes when no content modification is made.
- 🛠️ Fixing lost execute bits after cloning from a repository that enforces them.
- 🔒 Tracking permission changes explicitly in commits for audit or deployment.
Commands:
| Command | Purpose |
|---|---|
git ls-tree HEAD | Show file mode tracked by Git |
git update-index --chmod=+x file | Set executable bit |
git update-index --chmod=-x file | Remove executable bit |
git commit -m "..." | Commit permission change |
git config core.filemode true | Enable file mode tracking globally or locally |
Detail¶
Step 1 — Check current file permissions tracked by Git¶
Output example:
Here, 100644 means the file is not executable.
Step 2 — Update the permission flag¶
git update-index --chmod=+x script.sh # Make file executable
# or
git update-index --chmod=-x script.sh # Remove executable bit
Step 3 — Commit the permission change¶
Output:
[master 77b171e] Changing file permissions
0 files changed, 0 insertions(+), 0 deletions(-)
mode change 100644 => 100755 script.sh
Step 4 — Push to remote¶
Now, anyone cloning or pulling the repository will receive the updated executable permission.
Step 5 — (Optional) Ensure Git tracks permission changes¶
If permission changes are ignored, enable file mode tracking:
Or edit .git/config manually:
By default, git will update execute file permissions if you change them. It will not change or track any other permissions.
If you don't see any changes when modifying execute permission, you probably have a configuration in git which ignore file mode.
Look into your project, in the .git folder for the config file and you should see something like this:
You can either change it to true in your favorite text editor, or run:
Then, you should be able to commit normally your files. It will only commit the permission changes.