How Git Tracks File Executable Permission (+x)

Learn how Git tracks executable permissions on Linux, with practical commands to add, remove, and verify the executable bit.

In a Linux environment, Git tracks a file’s executable bit (+x). If you want a script to be preserved as an executable file in the repository, you need to explicitly record that permission change in Git.

Add Executable Permission to a File

1
2
3
git update-index --chmod=+x script.sh
git commit -m "chore: mark script.sh as executable"
git push

This command stages the executable-bit change for script.sh. After you commit and push, other users will keep the same permission state when they pull or clone the repository.

Remove Executable Permission from a File

1
2
3
git update-index --chmod=-x script.sh
git commit -m "chore: remove executable bit from script.sh"
git push

Verify the Result

Use the following commands to check file permissions in your working tree:

1
2
git clone xxxxxxxxxxxxxxx
ls -l script.sh

If you see something like -rwxr-xr-x, the file is executable. If you see -rw-r--r--, it is not executable.

Notes

  • git update-index --chmod=+x/-x only updates the file mode recorded by Git; it does not replace changes to file content.
  • In team workflows, it is best to commit permission-only changes separately for easier review and tracking.
记录并分享
Built with Hugo
Theme Stack designed by Jimmy