Git cannot checkout files with readonly permissions

I’m having some troubles with a git repository that have some files in readonly mode (chmod 0440).

Sometime, one of those files get modified on another branch ; and when you try to checkout that branch, git fails to update that file with a
warning: unable to unlink path/to/the/file: Permission denied

  • File and directory permissions on a cloned github repository
  • Appropriate file permissions for websites using Git and FTP
  • How to use group file permissions correctly on a git repository?
  • Structuring a central Git remote to serve production Apache sites
  • How to recover the file permissions to what git “thinks” the file should be?
  • set folder permissions when deploying cakephp app
  • The problem is that those files need to be in readonly mode, because the framework used beyond those files throws heavy warning messages when those files are writable, and even more problematic, each time we are (re)installing the framework in our continuous integration process, the framework updates those files to be in readonly mode.

    I tried to use git hooks to automatically chmod those files to 0664 before checking out any file/branch, then chmod them back to 0440, but I’m not sure such hooks exist.

    An unwanted solution would be to chmod myself those files to 0664 each time I know they could change with git, then chmod them back to 0440 to avoid pushing writable files in a prod environment, but it would lead to fails for sure.

    Another solution would be to commit them in 0664 mode and update our continuous integration process to re-chmod those file to 0664 after the framework is being (re)installed and totally ignore the warnings ; while keeping the chmod to 0440 for the prod environment.

    What you guys do you think of this problem, and what is the best solution I could have to fix it ?

  • How do I ignore all svn, bin, and obj folders when creating a git repository?
  • How to create branch and push to server
  • Why can I checkout a deleted Git branch, and why is it still available on GitHub?
  • Clone Git Repository on Apache Server
  • hudson + git + maven
  • Git Source Control Provider hotkeys
  • One Solution collect form web for “Git cannot checkout files with readonly permissions”

    Sounds like you are trying to use Git as a deployment tool.

    Git is not meant as deployment tool. One of the most important reasons is, that it doesn’t track permissions except for the user-executable one. If a file is read-only, Git of course cannot modify it, because it is read-only.

    Maybe you should read to get some hints on how to maybe be able to build a deployment tool around Git.

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