DEV Community

Matthew LaFalce
Matthew LaFalce

Posted on • Updated on

Checking File Permissions in your Git Repo

Files in Git are assigned either 644(owner rw-, group and other r--) or
755(owner rwx, group and other r-x). Ownership information is not
stored.

You can check the status of a file via:

git ls-files -s script.sh
Enter fullscreen mode Exit fullscreen mode

The output of this command is structured as:

[<tag> ]<mode> <object> <stage> <file>
Enter fullscreen mode Exit fullscreen mode

A sample:

100644 b43ebcdea6790f7f8018 0       script.sh
Enter fullscreen mode Exit fullscreen mode

The key piece above is the mode tag, 100644. The 100 prefix to the mode signifies that this file is a normal file. Then this is where you will see either a 644 or a 755 file mode.

As you can see, the file has 644 permission, and we want to change this now to 755:

git update-index --chmod=+x script.sh
Enter fullscreen mode Exit fullscreen mode

Inversely, we can remove the executable permission via:

git update-index --chmod=-x script.sh
Enter fullscreen mode Exit fullscreen mode

All that's left is to commit your changes!


bash
git commit -m "FIX: Changing file permissions"
[main 77b171e] Changing file permissions
0 files changed, 0 insertions(+), 0 deletions(-)
mode change 100644 => 100755 script.sh
Enter fullscreen mode Exit fullscreen mode

Top comments (0)