23

I am able to push fine, but I am suddenly getting this "fatal" message

$ git push
fatal: unable to connect to cache daemon: Bad file descriptor
Username for 'https://github.com':
Password for 'https://[email protected]':
fatal: unable to connect to cache daemon: Bad file descriptor
...

Why do I get this message all of the sudden? and what do I do?

I am not sure this might help, but between now and before this problem occurred

  • I was working on some branch that is not master
  • I changed my user.email in git config --global in the middle
  • my computer crashed big time because I connected the wrong project connector(that is not for the computer) to it, and I believe somehow some file got corrupted
  • After that occurred, when I tried to make a new commit,I was getting the following message : fatal: Failed to resolve HEAD as a valid ref.
  • Then I fixed it by modifying HEAD in config to "ref: refs/heads/master"
  • After coding and successfully committing the changes locally, when I tried to push it to the remote server, I got the following error message

    $ git push

    fatal: unable to connect to cache daemon: Bad file descriptor Username for 'https://github.com': Password for 'https://[email protected]': fatal: unable to connect to cache daemon: Bad file descriptor fatal: loose object 8ce710b1c78658e066cd2309b12b7766d1be4920 (stored in .git/objects/8c/e710b1c78658e066cd2309b12b7766d1be4920) is corrupt fatal: The remote end hung up unexpectedly fatal: The remote end hung up unexpectedly fatal: write error: Bad file descriptor

  • So I backed up all the changes I made, deleted the repo, clone the repo from the github, and made some changes with the backup files, add, commit, and pushed the changes fine...but still that message does not go away :(

1
  • I have colleague who gets a very similar error, except instead of "bad file descriptor", he sees "permission denied". But the push works, so "fatal" is obviously not fatal.
    – GTK
    Apr 9, 2013 at 1:21

6 Answers 6

36

https://stackoverflow.com/a/14160580

solved this for me:

sudo chown kev ~/.git-credential-cache/socket

replace kev with your user if you don't know your user:

whoami
2
  • 5
    chown: cannot access ‘/home/butko/.git-credential-cache/socket’: No such file or directory :/ But my error says: fatal: unable to connect to cache daemon: Permission denied
    – Luckylooke
    Apr 7, 2018 at 5:35
  • 1
    On recent versions of Linux (e.g. Ubuntu 18), as mentioned by Alwaysimproving below and also here -- gist.github.com/diegopacheco/ca7aeb7f6ce283d7d13b710f5301e969 -- this is the command that works: sudo chown $(whoami) ~/.cache/git/credential/socket Jul 14, 2020 at 19:08
11

Beware of manipulating ~/.git-credential-cache/socket (as with chown), for it has moved since 2014, as acknowledge by Git 2.13 (Q2 2017)
Adam K Dean also mention in the comments the path ~/.cache/git/credential/, which just needed chowning back to the user.

See commit 612c49e, commit 60759ba (17 Mar 2017), and commit e7f136b (13 Mar 2017) by Devin Lehmacher (lehmacdj).
(Merged by Junio C Hamano -- gitster -- in commit 78cf8ef, 24 Mar 2017)

credential-cache: use XDG_CACHE_HOME for socket

Make git-credential-cache follow the XDG base path specification by default. This increases consistency with other applications and helps keep clutter out of users' home directories.

Check the old socket location, ~/.git-credential-cache/, and use ~/.git-credential-cache/socket if that directory exists rather than forcing users who have used git credential-cache before to migrate to the new XDG compliant location.

Otherwise use the socket $XDG_CACHE_HOME/git/credential/socket following XDG base path specification.
Use the subdirectory credential/ in case other files are cached under $XDG_CACHE_HOME/git/ in the future and to make the socket's purpose clear.


Note: With Git 2.29 (Q4 2020), a handful of places in in-tree code still relied on being able to execute the git(man) subcommands, especially built-ins, in "git-foo" form, which have been corrected.

See commit c0e190c, commit 7cff3b6, commit 675df19 (26 Aug 2020) by Junio C Hamano (gitster).
(Merged by Junio C Hamano -- gitster -- in commit 18aff08, 03 Sep 2020)

credential-cache: use child_process.args

As child_process structure has an embedded strvec args for formulating the command line, let's use it instead of using an out-of-line argv[] whose length needs to be maintained correctly.

Also, when spawning a git subcommand, omit it from the command list and instead use the .git_cmd bit in the child_process structure.

So, no more call to git-credential-cache--daemon, but rather git credential-cache--daemon.

2
  • 5
    In my case, the path was ~/.cache/git/credential/ which just needed chowning back to the user. Sep 12, 2019 at 7:55
  • 1
    @AdamKDean Thank you. I have included your comment in the answer for more visibility.
    – VonC
    Sep 12, 2019 at 8:34
4

This error comes when you try to commit using "sudo".
so the password saved is for "sudo" user only,

But when you try to commit as a normal user,
This error happens, permission denied for normal user
you can get rid of this error by using above answer Kev Price

2

Quick solution

Here is the single command you need to solve the issue.

sudo chown $(whoami) ~/.cache/git/credential/socket

Read the other answers if you want a deeper understanding of what causes this issue.

0

Try to set global gitconfig.

git config --global user.name "your username"
git config --global user.email "your email address"
2
  • try explaining why your answer is helpful
    – Claire
    Jul 2, 2019 at 10:51
  • 1
    how is this answer related to the question ? Nov 4, 2019 at 17:47
0

It can be due to your first setup as root user, and then you want to use git as another user.You can change the git cache permission:

chown -R user:user_group ~/.cache/git/

Your Answer

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.