Git changes my file permissions upon checkout

Our workflow is develop on a local machine, commit the changes to a central repository, then check out the branch of that repository that we need.

The problem is that Git changes ownership and even file permissions of the files that it checks out, depending on the user making the checkout. A direct result of this is that our CSS files become unreadable after a checkout, as Git changes the file ownership to the person who did the Git pull in the webroot.

  • Why there is no response using git protocol to clone project?
  • Subtree-split with empty-ident commit; or, deleting a commit without rebase: an unusual use-case
  • Git Submodule to a subfolder
  • How many commands does Git have?
  • Does local info about remotes transfers on remote origin
  • Managing .git file size
  • Example:

    • Before git pull: style.css owned by user_a:group_a
    • After git pull: style.css owned by user_b:user_b

    I want to keep ownership as user_a:group_a. I don’t want to have to log in every time one of my team has made a change to the files, and change the ownership back to the original configuration.

    How do other people deal with this? How do you deal with repositories used by multiple users. We have suphp on our system and cannot take it off.

  • How to create a patch with git-extensions
  • Add ignored file to repo but don't track afterwards
  • SourceTree (Git) Relative Date Format?
  • git-svn rename tracking branch
  • msysgit multi command alias
  • Show list of tasks to asssociate when commiting to a git repository from Visual Studio 2008-2013
  • 6 Solutions collect form web for “Git changes my file permissions upon checkout”

    Git does not change file permissions or ownership. It’s just that it (mostly) doesn’t store it either, it doesn’t exist in your repo, so they get changed to whatever your user has. Just like with any file creation.

    Git supports two permission sets: executable bit on and executable bit off. Nothing else. Ownership information is not stored at all.

    See this thread – “If you want specific permissions, you’ll need to do it manually.”

    There are some solutions suggested: you can use a separate tool to do it for you, use a proper combination of user account and umask to set them properly by default or write a git hook yourself to do it. A hook would’ve to be installed on the user doing the checkout.

    Like @ikke said in the comments, Git is not really a deployment tool and should not be used as such. It is a version control system for source code.

    For me, the best solution was creation of a shell script that fixes the permissions. For example:

    chmod +x  tools/*

    Btw, checkout is not the only case when git does mess with permissions, it’s also when you pull. I handle that with .git/hooks/post-merge hook.

    Ideally, you can create a shell script that fixes permissions somewhere in your repo (e.g. tools/, and call it in both hooks. Don’t forget to change the permissions for that file manually 😉

    chmod a+x tools/

    The easiest solution is to just run git as user_a.

    One possible solution to you problem could be here: Retaining file permissions with Git

    It worked for me, so you can try and see how it works for you.

    I often run a

    git checkout -f file.xml

    … on a versioned file.xml with world-write permissions, as I continually modify it and want to return it to the normal state.

    But that resets the permissions. A slightly longer version:

    git show HEAD:./file.xml > ./file.xml

    Just resets the content.

    Alternatively you can set a default permission for the folder in question like so:

    Git Baby is a git and github fan, let's start git clone.