
Problem
On a recent project I was using a Windows laptop for coding and committed my code to a remote git repo hosted in Atlassian BitBucket. As part of the project, I created some bash scripts which needed to run in a Linux Docker container through Bamboo, and I found that they wouldn’t execute due to not having execute permission set on the files.
Solution
Looking deeper into this, I found that whenever you create a file on Windows it always assigns read-write permissions by default to the owner of file, regardless of the type. This translates through to the file mode used by git when the files is committed.
To fix:
- Navigate to the folder containing the script(s) for which permissions have to be changed
- check the existing file mode by the using the following command:
git ls-files --stage
You should see output like this. The 100644
shows the file mode:
100644 1dd895687b598e58c1d0e60b7985aab8957b9c8b 0 test.sh
- To change the file mode run:
git update-index --chmod=+x 'name-of-shell-script'
- check the file mode again by running:
git ls-files --stage
The file mode should now have changed to
100755
- You can now commit the file(s) back to the git repository and they will be executable in Linux.
Leave a Reply