Edward Thomson

Setting Files Executable in Git on Windows

June 9, 2015  •  11:36 AM

Sometimes you need to check an executable into your Git repository and - even though Windows doesn't really have a concept of an "executable bit" - you might need to set it executable for the other platforms.

For example, a handful of my native code projects use the very clever clar project for unit testing. Clar uses a Python script to introspect your unit tests for the actual test functions and generate the harness. It's handy if this generator is executable on Unix boxes and - thankfully - Git will let you set it executable even on a Windows box.

Once you've staged your file, you can set it executable with the git-update-index --chmod=+x command. For example:

C:\Repo> git add generate.py
C:\Repo> git update-index --chmod=+x

And now you can ensure that the file is executable by inspecting the index:

C:\Repo> git ls-files --stage
100755 587efb519c0ab60692e8d4c19f3471e0dbbecd3d 0       generate.py

If you're familiar with Unix permissions, then you'll note that first column looks like a Unix permission. Indeed, coming from a nice Unix heritage, Git uses the mode 100644 to represent a non-executable file and 100755 to represent an executable file.1

Now when you commit this change and check it out on a Unix system, generate.py will be set executable!

  1. Note, however, that this only looks a lot like a Unix permission. Regardless of the file's actual permission, Git only stores 100644 for regular files and 100755 for executable files. Effectively, this only stores whether a file is executable or not.