Skip to content

Instantly share code, notes, and snippets.

@lelegard
Created December 7, 2021 08:32
Show Gist options
  • Save lelegard/3f9c268ba08b35efc3ef3d72a882b364 to your computer and use it in GitHub Desktop.
Save lelegard/3f9c268ba08b35efc3ef3d72a882b364 to your computer and use it in GitHub Desktop.
Git on Windows: setting executable permission on a script

Git on Windows: setting executable permission on a script

The problem: Create a script (shell, python, whatever) on Windows, add it to a git repository. Then clone or pull the repo on a UNIX system (Linux, macOS). The file won't get the executable permission.

If the script had been created from the beginning on a UNIX system with executable permission, this permission would have been propagated to the repo. However, on Windows, this type of permission does not exist and cannot be set at system level.

On Windows, to enforce the execution permission in the repo for a given script, use the following command to add the file:

$ git add --chmod=+x  the-script.sh

If the script had already been added in the index, you can modify the permissions in the index:

$ git update-index --chmod=+x  the-script.sh

To verify the permissions in the index:

$ git ls-files --stage  the-script.sh
100755 991ba25219c4441389de0f50b70fb59872a9c07f 0       the-script.sh
   ^^^
@Riches
Copy link

Riches commented Jun 5, 2024

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment