I'm getting a 'permission denied' error on a git alias. It works with root but not my user account:

$ andy@ubuntu:/usr/local/bin$ sudo git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
$ andy@ubuntu:/usr/local/bin$ git lg
    fatal: cannot exec 'git-lg': Permission denied
$ andy@ubuntu:/usr/local/bin$

Any Ideas?


There's an entry in your $PATH pointing to a directory that you can't access, and you're using a version of git earlier than

When you run git lg git first does some setup, including adding an entry to the copy of the $PATH that it is using. Then it tries to run the command git-lg, so that a command would override the alias. When it does that it's getting the permission denied error shown in your output.

Older versions of git would stop at that point. Starting with version, it will treat that error the same as the command just not being found.

When you ran that as root git was able to look through all of the directories in the $PATH, see that no git-lg command exists, and so it would go on to use the defined alias.

To fix the problem you can upgrade to a newer version of git. The other option would be to make sure that you have permission to access all directories listed in your $PATH, either by granting additional permissions on any that are a problem or by not including those in the list.

  • Thank you! It appears, after rebooting, I can now use the command – andy Feb 22 '13 at 15:51

To complement on qqx's answer (https://unix.stackexchange.com/a/65768/253433).

Therefore if you restrict PATH to a list of path for which you have the proper rights, there is no problem:

PATH=/usr/bin git lg

Or more persistently:

alias git='PATH=/usr/bin git'
git lg

Thanks qqx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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