Troubleshooting Git Fatal Error: Failed to Read Object Xxx: Invalid Argument

Recently, I was facing the git fatal error when I pull new changes from remote repository, This is probably due to my computer was shutdown due to power cut, I had faced similar error previously and I’ll explain that we well in my next post

I was getting the following error when I use git pull command

Error when loading gists from https://gist.github.com/.

I was able to switch to another local branch, I was able to create new local branch from few remove branches but not all. I was also able to make new commit in local repository. This means I git repository is not crashed fully but there are some issues with refs (SHA1 hash pointers).

For the branches where you can not pull or fetch, you should get the following output.

Error when loading gists from https://gist.github.com/.

Now, backup your .git folder first. Then use git fsck command to see if there is an error. I got following output

Error when loading gists from https://gist.github.com/.

I deleted the file .git/objects/38/fe6f16c7e8246d61150f0bc42629dbb532b5ce and continuing these steps until I get following output:

Error when loading gists from https://gist.github.com/.

Output says that 3 remote rerfs are invalid. I removed those 3 refs (.git/refs/remotes/origin/master, .git/refs/remotes/origin/staging, .git/refs/remotes/origin/development) and voila! I was able to pull and push.