Git is changing my file’s permissions when I push to server

This thread post offers a very good explanation:

This is by design. While the git data structure can technically store
unix mode bits in its trees, it was found early on in git’s history
that respecting anything beyond a simple executable bit ended up being
more cumbersome for git’s normal use cases (i.e., people storing code
or other shared files in a repository).

We could add in a config option to respect file modes, but it has
generally been seen as not worthwhile. It solves only a part of the
general metadata problem, as it omits owner and group names or ids, as
well as extended metadata like ACLs.

If modes are important to you, the suggested fixes are one of:

  1. Use a tool like “metastore” that can be called from git hooks, and
    will save and restore file permissions in a file that is tracked in
    the repository. Do note that when using such a tool there is a race
    condition in protecting files (i.e., git will create your file as
    644, and then metastore will correct it to 600; in the meantime,
    somebody could read your file).

  2. Depending on exactly what you’re storing, it may make sense to keep
    your repository in another directory, protected by permissions, and
    then use a separate tool to deploy your files from the repository
    to their ultimate location (e.g., a Makefile or other install
    tool).

Leave a Comment