Last Updated on February 16, 2025
with Windows Subsystem for Linux
git update-index --chmod=+x myfile.sh
If you frequently work with .sh
files and want to ensure they are always marked as executable, you can configure Git to automatically handle this. For example, you can use a .gitattributes
file to define rules for specific file types.
*.sh text eol=lf *.sh executable
a .bat
script for Windows that searches for all .sh
files in a folder and its subfolders, and then runs the git update-index --chmod=+x
command for each file:
@echo off :: Get the current directory set "ROOT_DIR=%cd%" :: Navigate to the current directory cd /d "%ROOT_DIR%" :: Loop through all .sh files in the folder and subfolders for /r %%f in (*.sh) do ( echo Processing file: %%f :: Add the file to the Git index if it's not already tracked git add "%%f" 2>nul :: Mark the file as executable git update-index --chmod=+x "%%f" ) echo All .sh files in the current directory and subfolders have been marked as executable. pause
References
https://www.scivision.dev/git-windows-chmod-executable/