can't add all files to git due to permissions

Viewed 83267

I want to add all the files in the current directory to git:

git add .
error: open(".mysql_history"): Permission denied
fatal: unable to index file .mysql_history

That's fine. That file happens to be in this directory and owned by root. I want to add all other files. Is there a way to do that without having to manually add each file by hand?

I know that I could add the file to exclude or .gitignore, but I'd like to have it just ignore things based on permissions (there's a good chance other files like this will end up in the directory, and adding them to .gitignore all the time is a pain).

16 Answers

Use git add --ignore-errors .

This will still give an error for the unreadable file(s), but not a fatal one. The other files will be added.

Closing your IDE or whatever that uses the relative files you want to upload solved my problem

Would it help if you added that file to your .gitignore file? So all other files would be versioned and that file would get ignored (unless you need it).

Just exclude the file. You can add .mysql_history to a .gitignore file, or add it to .git/info/exclude.

Adding an entry to .gitignore will propagate the setting with the repo (since .gitignore is stored with the repo); adding it to .git/info/exclude makes it "personal" because this file is not propagated with the repo. Either way, .mysql_history will be ignored by git-add and friends.

You can read more about ignoring files with Git on this man page.

I was using @matli's solution but still having troubles sometimes.

I ended up using

git add --ignore-errors --force .

Closed all instances of visual studio worked for me

Check if there is some task/process related to those files running in background.

I realised trying to empty my Temp folder. When a file cannot be erased, Windows informs you which is the process related to. Killing that process solved me the problem.

That's why finishing the IDE or restarting the system usually works.

In my case, I was trying to add excel file to git, but those excel file where opened, hence 'git add' was trying to add the $filename.xlsx(the file which gets created along side the original file while we are working on an opened instance of that file).Closing the excel file worked for me

The first thing you have to know that why the error occures? This mainly due to git command running on un related file group or a file that is owned by root or its own but you need an allivated access. This is mainly in Linux.

If this for windows try using file/folder property setting and adding user to the list of permission.

In linux you have mainly three(3) options.

1. run git as

> sudo git add .

2. run git command as

git add --ignore-errors  -force .

3. change file or folder who is issuing permission deniedn with sudo access or default user account.

chmod 755 /direcroty/file.html 
  1. adjuts your curernt user account to access denied file evenif,with sudor permsiions and adjustemnt.

you can change directory permission to ignore this error : e.g. sudo chmod -R 777 directory

Please Specify file name you want to add; example:

git add index.html

I hope this helps you also

Restarting system (Windows) solving my problem.

This idiot (me) tried to add files to git that were on onedrive (terrible place for a git repo I know), without onedrive running...

Related