250

I've read through a few questions regarding file permissions in Git and I'm still a bit confused. I've got a repo on GitHub forked from another. Post merge, they should be identical. However:

$ git diff --summary origin/epsilon master/epsilon
 mode change 100644 => 100755 ants/dist/sample_bots/csharp/compile.sh
 mode change 100644 => 100755 ants/dist/starter_bots/coffeescript/MyBot.coffee
 mode change 100644 => 100755 ants/dist/starter_bots/coffeescript/ants.coffee
 mode change 100644 => 100755 ants/util/block_test.sh
 mode change 100644 => 100755 manager/mass_skill_update.py
 mode change 100644 => 100755 worker/jailguard.py
 mode change 100644 => 100755 worker/release_stale_jails.py
 mode change 100644 => 100755 worker/start_worker.sh

I've tried changing file permissions, but it does not alter the diff results.

7 Answers 7

486

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>
9
  • 9
    +1: exactly what I needed to make sure the shell scripts I commit from Windows (where I have core.filemode set to false) actually have the execute bit set.
    – tomlogic
    Oct 24, 2013 at 22:00
  • In my case I also added a new line to the file, and only then was able to commit
    – oshai
    Jul 7, 2016 at 18:46
  • 10
    In Windows, using git-bash, I needed a --add flag to the execution for some reason: git update-index --add --chmod=+x <file>. After this, the file was already in stage with the chmod Oct 16, 2019 at 18:43
  • 1
    Has no effect anymore, neither in git bash nor in cmd.exe prompt.
    – Ben
    Mar 16, 2020 at 17:14
  • 3
    @Ben you also need to remember to not to say things like "Has no effect anymore" without being sure of it 😂
    – Erdal G.
    Mar 4, 2021 at 7:13
153

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

First see what core.filemode is set to -

git config core.filemode

Try setting it to false:

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.
7
  • 1
    Thanks. I saw that too. Tried it and it made no difference.
    – Synesso
    Jun 25, 2011 at 8:04
  • 4
    I had similar problems to the OP and couldn't pull changes no matter how hard I tried to reset. This did the trick for me. Oct 13, 2011 at 9:10
  • 15
    [project]/.git/config may contain the same setting and will override ~/.gitconfig. If you're trying to set it globally, make sure it isn't being overridden locally. Jan 31, 2013 at 19:56
  • 6
    I find this is necessary on NTFS as well, sadly.
    – Marc.2377
    Apr 30, 2019 at 17:15
  • 3
    That's the answer! Apr 14, 2020 at 8:30
38

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.

1
  • 1
    It is better to avoid using xargs (deeper explanation on why can be found here). Try instead: find . -name '*.sh' -type 'f' -exec git update-index --chmod=+x {} + . This will execute the command for each file that find finds. Nov 24, 2021 at 16:57
24

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.

20

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

NB: If you are running Windows and deploying on Linux, be sure the repository contains code with Unix-like line endings. To bulk-convert files, you could try dos2unix.exe, or work in Git Bash.

3
  • Is there no way to do something like git update-index --chmod=1777 'scriptname.ext'? Jun 14, 2019 at 18:07
  • Did you navigated to the path , where the script file exists? @alex Jun 15, 2019 at 11:29
  • Thanks for showing how to check permissions.
    – Livven
    Nov 24, 2021 at 16:38
5

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.

1
  • I cna recommend GitHub for windows. Wonderfull interface and really nice shell, I even made relativly easy ssh key setup and git flow install.
    – Sangoku
    Oct 25, 2013 at 10:57
0

In my case, I accidentally shifted the shebang line so that

#! /bin/sh

became

   #! /bin/sh

This fails the git-bash permission check. After removing the leading whitespaces, the script becomes executable again.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.