0

How can we have git automatically add chmod permissions for executables when committing?

I have a directory on my Windows, where I've created some executable files (shell scripts and binaries themselves). git bash reveals this.

-rw-r--r-- Makefile
-rw-r--r-- file.c
-rwxr-xr-x file-test.sh* [executable]
drwxr-xr-x subdir/ [might have some executable inside]

What I would like is that when I clone onto my Linux, the permissions be the same.

Normally, I just git add . && git commit -m "test" && git push and git pull from the other side, but on Linux the executable permissions are lost:

-rw-r--r-- Makefile
-rw-r--r-- file.c
-rwxr-xr-- file-test.sh [not executable]
drwxrwxr-x subdir/ [all files inside are not executable]

I instead tried to run git add . --chmod+x on Windows git bash, but this turned everything into an executable, not just what was originally an executable:

-rwxrwxr-x Makefile* [executable]
-rwxrwxr-x file.c* [executable]
-rwxrwxr-x file-test.sh* [executable]
drwxrwxr-x subdir/

The alternative is manually changing each permission on my Windows through git update-index --add --chmod=+x file-test.sh subdir/..., but this is not what I want.

How can we commit the executables permissions without specifying this manually?

I prefer not to go down a script path and only use git if possible

K Split X
  • 3,405
  • 7
  • 24
  • 49
  • Windows doesn't have the "executable bit" the same way as Linux does, so there is nothing to "copy". – knittl Jan 14 '23 at 18:08
  • Does this answer your question? [windows subsystem for linux preserve file attributes in git repo](https://stackoverflow.com/questions/48377612/windows-subsystem-for-linux-preserve-file-attributes-in-git-repo). [@knittl looks like there might be a way?] – Inigo Jan 16 '23 at 05:33

0 Answers0