How to change file permissions in Git on Windows
Make a Git repository file on a local Windows machine executable by changing the CHMOD value, which can be transferred to the repository following a push.
Sometimes its important to set a file to executable whilst it is stored in a repository on a Windows machine so that it can be executed when it’s pushed to another server or platform via Git.
To do this, cd
to the repository on your Windows machine and check existing CHMOD values:
git ls-files --stage
The output should show values for each file in your repository, either 100644
(not executable) or 100755
(executable).
To make a file executable, enter the following command:
git update-index --chmod=+x path/to/file.ext
In the example above, the file /path/to/file.ext would become executable. To change this back, change +x
to -x
:
git update-index --chmod=-x path/to/file.ext
Now, re-enter git ls-files --stage
and it should be apparent that the CHMOD values for the file have changed.
Now check your files back into GitHub:
git commit -m "Made file.ext executable"
git push
Unfortunately Git stores only one bit for file permissions so it’s not possible to change CHMOD values to something else, such as 0750
in Windows. Nevertheless, the above approach will ensure that the files are executable on the other server.
Comments
2 responses to “How to change file permissions in Git on Windows”
Simple and useful, thanks!
A hidden nugget of information!