Change file permissions when working with git repo’s on windows

Dharmendra Singh
2 min readJun 9, 2017

--

Here was the problem :

I use a windows laptop for checking in files into git repo. My git repo contains few shell scripts which needs to be executed on Linux/unix server. In order to execute a shell script on unix/linux server you need to have execute permissions on the file. Whenever you create a file through windows based systems it gives you a read-write permissions by default to the owner of file … so here is the issue if you need to provide execute permissions to a shell script file being checked on from a windows system you are stuck.

I struggled with this annoying issue for a while and invented a time consuming hack where i used to check-in the shell script in read-only mode from a windows system …as that’s what i had.Login to a remote linux/unix/mac server(you need to get it from cloud or loan it from someone) check-out from git repo , change the file permissions to execute and then check-in the shell script file again to the repo.

Pretty bad huh !!!

Mind it folks who are having Mac laptops also will not realize this issue as you can change file permissions there the same way you do it Linux.

Now the fun part was to figure out a solution for this nagging issue :)

The solution :

Most of the folks on Windows working with git repo’s use windows git bash for doing git check-ins and check-outs to/from from git repo…. if you are already not using it i will highly recommend use it… pretty neat tool for windows os.

  • Navigate to the .sh file for which permissions have to be changed to execute through gitbash
  • check the existing permissions by the using the following command git ls-files --stage the command will show you the current file permissions like 100644
  • Now git bash has command to update the file permission to execute looks like :D git update-index --chmod=+x 'name-of-shell-script'
  • check the file permission again git ls-files --stage ... now the file permissions will be like 100755
  • Now check-in the files back to github with new permissions git commit -m "made a file executable" and push the code to repo git push

--

--