12

Im using GitHub on Windows and after working fine for the whole time, when I opened it today, it says:

Failed to load commit history for this repository. You might need to open a shell and debug the state of this repo.

And then:

Failed to get list of branches.

When I open shell and try git status or whatever other command, it returns this error :

fatal: bad config file line 1 in .git/config

Not sure what to do with that? I read someone saying to replace the config file with an earlier version of it, but I dont have an earlier version..

Dom
  • 1,377
  • 1
  • 10
  • 16
  • I hit an identical problem this week with a newly created repo that has only one branch. I fixed it by copying the origin and master sections from the config file of another repo (and editing the one obvious line). – malcanso Jul 18 '15 at 16:39

8 Answers8

20

I solved this by

  1. open .git/config file
  2. clear all the NULL values in the file
  3. save and close the file
  4. git add .
Issaka Faisal
  • 237
  • 4
  • 5
  • This helped me too. I was getting the same error just that n line number 16. I removed the last line which was actually just a whitespace. Saved the file and it worked. – Deepika Anand Dec 05 '18 at 21:21
  • I had issue in shallow file. I removed all null values and it worked. Thanks :) – Kumaresan Lc Oct 25 '19 at 11:44
9

My question might have been abit vague, but I wasnt sure myself what happened. I solved it by finding .git/config file on my laptop using Windows search , and deleting it. Then I deleted content of my github folder and cloned the repo again and it worked after :)

Dom
  • 1,377
  • 1
  • 10
  • 16
5

I solved this on my mac by

  1. created a .gitconfig file in $HOME(cmd + shift + h) folder
  2. added [user] name = myname email = myemail@example.com in the .gitconfig file
  3. saved and replaced with the existing file

now all git commands started working

TerribleDeveloper
  • 513
  • 2
  • 7
  • 20
  • exactly. In my case: [user] name = name.surname email = name.surname@mail.com [core] autocrlf = true [push] default = simple – Laura Liparulo Sep 11 '17 at 08:36
3

I had got same problem and i removed the .gitconfig file from local repository .The prroblem is resolved.

1

I was with Visual Studio Code and facing the same issue. I went to ".git>config" file and cleared that file, saved it. enter image description here

That fixed the issue.

Raghav
  • 7,498
  • 5
  • 74
  • 97
1
  • Open Terminal and type cd $HOME to navigate to user's home.
  • Then type vim ~/.gitconfig to navigate to .gitconfig file.
  • Press 'i' which gives Insert.
  • Make sure the second line in that editor consists only '[user]', if there's any commit name, delete it.
  • After changes if any, press 'escape button' and type ':wq'.
  • After this, you can continue with the regular git setup config methods for name and email.
Victor
  • 2,270
  • 2
  • 23
  • 52
1

c:/users/username/.gitconfig

delete .gitconfig file from given location in your pc and then write git init. it would be work properly

  • HI mani :) Welcome! Your answer is very similar to the accepted answer and as such will likely be marked as a duplicate. I'd recommend looking at all existing answers on questions such as this, which are years old. – tjheslin1 Mar 28 '22 at 18:44
-2

I just deleted all the contents of .gitignore and ran the following commands:

git config --global user.name "give your user name here"    
git config --global user.email "your.email.id"

note: I had just installed git on my pc so there weren't much changes in .gitignore file so i guess it was safe to clear everything.