Jing Lan
Jing Lan

Reputation: 179

unable to access '/Users/dida/.config/git/attributes': Permission denied

When I do some git operations, such as 'git diff' or 'git add .', it shows that warning:

unable to access '/Users/dida/.config/git/attributes': Permission denied 

I wonder which config I did wrong and how can I fix it?
It's better with some commands, I am using mac command line

Upvotes: 17

Views: 27154

Answers (6)

RaavanSita
RaavanSita

Reputation: 7

warning: unable to access '/Users/raavan/.config/git/ignore': Permission denied warning: unable to access '/Users/raavan/.config/git/attributes': Permission den

ok! if you had something similar, this is the solution. use sudo command

sudo git add --all, sudo git commit -m ""

this will work and worked for me in mac os.

if anyone knows why the sudo command worked or alternative way please respond!.

Upvotes: -1

Ben Butterworth
Ben Butterworth

Reputation: 28472

Upon finding out more information on the file, I noticed the file was not owned by my user("ubuntu"), but by "root" instead.

ls -dl /home/$USER/.config to find out the user and group of the file


sudo chown $USER -R /home/$USER/.config to update the user of the file sudo chgrp $USER -R home/$USER/.config/ to update the group of the file to the your current user

Now, when you get the file details using ls again, you'll see the information was updated.

That fixed it for me.

Upvotes: 1

50chickens
50chickens

Reputation: 21

try sudo -u user --set-home git clone http://github.com/repohere this worked for me.

Upvotes: -1

Ria Anggraini
Ria Anggraini

Reputation: 2655

Cause

Git reads config settings from a variety of paths and the doesn't have access to some of them.

Git tries to read root config setting instead of config settings due to the starting script using su command with do not reset environment variables option (-m):

/bin/su -m $USER -c "cd $BASE/logs && $BASE/bin/startup.sh &> /dev/null"

Bitbucket Server is being started as root with /etc/init.d/atlbitbucket start script. Since the init.d script calls start-bitbucket.sh which uses su -m this causes the environment variables for root to be preserved and atlbitbucket does not have permission to write in the root home directory.

Git was compiled from source using the default settings which prevents any users other than the one that compiled Git from running it

Resolution

Fix the permissions on the files and directories with regard to the Bitbucket Server user performing the command:

chown <USER>.<GROUP> -R /home/<USER>/.config
chown <USER>.<GROUP> -R /home/<USER>/.gitconfig

(info) Change the USER.GROUP by your username and group in your OS.

If Bitbucket Server starting script have su command, make sure that the option -m is not used.

If Bitbucket Server is being started with /etc/init.d/atlbitbucket start switch to starting Bitbucket Servering with service atlbitbucket start

To have Bitbucket Server automatically start at boot, run chkconfig atlbitbucket on

Recompile Git using more sensible defaults:

make prefix=/usr/local/git all
make prefix=/usr/local/git install

or maybe this articles could help you https://confluence.atlassian.com/bitbucketserverkb/permission-denied-on-git-config-file-779171763.html

Upvotes: 7

VonC
VonC

Reputation: 1323263

git uses the HOME and XDG_CONFIG_HOME environment settings to lookup the config files.

Make sure they are set properly, to your current user (check the result of the id command)

id -a

Check also git config -l --show-origin to see where Git is trying to access those config files.

Upvotes: 1

phd
phd

Reputation: 94407

Seems you've run sudo -H and sudo changed the ownership of some files to root. Take the files back:

sudo chown -R dida /Users/dida

Upvotes: 25

Related Questions