sandypockets
sandypockets

Reputation: 409

Broke git config file

I just pushed some files to a GitHub repo from my physical computer instead of my VM, and noticed that my name was displaying differently. So, like a fool, I edited the git config file, and changed my name and email address to match what I was using on my VM. Of course, git won't run at all now. I just get the following error when I try any git commands now;

fatal: bad config line 1 in file /Users/<myusername>/.gitconfig

I have the old values written down, so I can revert them that way if that's helpful, but I can't figure out how to edit that file again, as it is hidden (with good reason).

I'm on MacOS, Big Sur 11.2.2.

I used git config --global --edit to open the file, then used the editor in the terminal (vim?) to adjust the file.

I just reopened the file, and changed it back to what I think is the original, but still getting the fatal error. The file looks like this currently:

 This is Git's per-user configuration file.
[user]
# Please adapt and uncomment the following lines:
#       name = <myname>
#       email = <myname>@<myname>-mbp.lan
~                                                                                                                                                    
~                                                                               
".gitconfig" 5L, 153C

Any help is greatly appreciated.

Upvotes: 1

Views: 675

Answers (1)

sandypockets
sandypockets

Reputation: 409

I followed along with the comments, and the solution was to:

Add the # to the first line, first col of the file. I had already deleted it at this point, but recreating it entirely seems to have done the trick.

The steps I followed were:

  1. rm .gitconfig
  2. touch .gitconfig
  3. vim .gitconfig
  4. i to insert text
  5. Pasted in the previous contents of the file, using the old name and email that was working in the first place, and added the missing # from line 1 col 1.
  6. Save and quit Vim esc, :wq

All seems to be working again!

Big thanks to everyone that jumped in via the comments!

Upvotes: 1

Related Questions