13

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,427
  • 1
  • 12
  • 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

9 Answers9

23

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
  • 267
  • 3
  • 5
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,427
  • 1
  • 12
  • 16
6

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
  • 553
  • 2
  • 8
  • 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.

2

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
  • 8,772
  • 6
  • 82
  • 106
2
  • 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,450
  • 2
  • 23
  • 54
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
0

This is the easiest solution. If the folder files not modified.

You can clone the same git in another folder of same server.

Just try to replace the entire .git folder.

config with below,

git config user.name "username"
git config user.email "youremail"

Note: this only applicable if there is no change in codes also Not suggested for live server.

-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.