Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git file permissions on Windows

People also ask

How do I give Git permission to run a file?

The solution is to use the Git update-index command to assign the execute permissions. This will assign execute permissions to the bash file. After that you can commit the changes to the repo.

How do I see file permissions in Git?

Use git ls-files -s <file> : Show staged contents' mode bits, object name and stage number in the output. Note that Git only tracks files' executable bit. You'll only ever see 644 or 755.

Are file permissions stored in Git?

1 Answer. Show activity on this post. When Git checks out files, it by default uses the umask of the file on the system, setting the executable bit if it's a directory or it's marked as an executable file. That's because Git removes and re-creates the file, so it doesn't preserve the permissions of the existing file.

What are 644 permissions?

Permissions of 644 mean that the owner of the file has read and write access, while the group members and other users on the system only have read access. For executable files, the equivalent settings would be 700 and 755 which correspond to 600 and 644 except with execution permission.


I found the solution of how to change permissions (also) on Windows here: http://blog.lesc.se/2011/11/how-to-change-file-premissions-in-git.html

For example following command adds user execute permission to an arbitrary file:

git update-index --chmod=+x <file>

From another question here on stackoverflow: How do I make Git ignore file mode (chmod) changes?

Try:

git config core.filemode false

From git-config(1):

   core.fileMode
       If false, the executable bit differences between the index and the
       working copy are ignored; useful on broken filesystems like FAT.
       See git-update-index(1). True by default.

Handy one-liner for Git Bash:

find . -name '*.sh' | xargs git update-index --chmod=+x

It will mark all .sh file as executable. After that, you just have to git commit.


If you use Cygwin git (or Linux git, too, I assume), there's a good chance your core.filemode setting has been set at the project level in $projdir/.git/config . I found that I had to do the following to get my Cygwin git and my Windows git to coexist nicely on a Windows filesystem without nonexistent filemode changes showing up all the time:

  • delete the line setting core.filemode in $projdir/.git/config
  • in Windows git, run "git config --global core.filemode false"

This allows my Cygwin git to continue to see filemode changes, which are usually relevant, while instructing the Windows git to ignore the filemode changes it sees, which are usually false positives.


First check file permissions using below command.

git ls-files --stage

Then change permissions. Here "x" represents execute permissions.

git update-index --chmod=+x 'scriptname.ext'

Now re-verify the permissions.

git ls-files --stage

==============================================

if you are using Windows PC, but deploying on linux machine. Execute the below command in the first place to make it compatible to run on linux machine

dos2unix scriptname.ext scriptname.ext


I fixed it by changing the file permissions in Ubuntu, commit, push and all OK. Seems it just wouldn't work with msysgit on Windows/NTFS.