git update-index --chmod=+x path/to/file

git update-index --chmod=-x path/to/file

Deeper look

100644 for all regular files

for all regular files 100755 for executable files

--stage

$ git ls-files --stage 100644 1ff0c423042b46cb1d617b81efb715defbe8054d 0 .gitattributes 100644 3c4efe206bd0e7230ad0ae8396a3c883c8207906 0 .gitignore 100755 1a82e9a4560497d8c6e273c61bfd01995524d58f 0 my_executable_script.sh

At my work, I am working usually with Windows. But when we started our migration to Linux Docker containers and Kubernetes, I've found one annoying issue. Once you create a bash file on Windows, push it to Git and after this, you try to execute this file in most cases, you will get a “Permission Denied” error. But it turns out the solution is quite easy. So I am sharing it here, so it can maybe help you (or me) in the future.The solution is the Git update-index command.To set the execute permission you can use this command:To remove it, use:This will assign execute permission to the selected bash file. The only thing missing is to push the changes to the Git repository.Let's check what is happening here underhood. Under the hood, Git doesn't have a unix files permission system. In reality, Git maintains a special "mode" for each file in its internal storage:By default, when you add a file to a repository, Git will try to set the correct file mode accordingly. But sometimes it fails.To check file's file mode you can use ls-files command with the optionThank you for reading, I hope this will help someone.