Git Error - key does not contain a section

55,909

Solution 1

Indeed, the problem is in .git/config. You probably edited it and you removed the name of the section by mistake.

The values in Git config file are grouped in sections. The name of each section is placed between square brackets on a separate line.

The values you posted (from the beginning of your .git/config) should stay in the core section. Make your .git/config file look like:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ...

Solution 2

paste the following code to terminal it will open global config file in VI text editor

git config --global --edit

press i to write in VI text editor and remove all the text and paste the following

[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true

to save in VI press ESC and :wq and press enter

Solution 3

This is not your case, but responding here for other people with the same issue as me. I had this error message:

error: key does not contain a section: name
error: key does not contain a section: email

It turns out I had messed up something in my ~/.gitconfig file.

To fix it, I looked at this example and realized the first section of that file should look like this (fake example data):

[user]
    name = Bart S
    email = [email protected]
    username = barts

This fixed it for me.

Solution 4

Git configuration is organized in sections.

It's:

Your .git/config should look like this:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    # ...

Solution 5

git config [section] solutions

fix git [section] warnings

  1. global config
$ vim ~/.gitconfig

[user]
  email = [email protected]
  name = xgqfrms


$ cat ~/.gitconfig

  1. project local config
$ vim .git/config

[core]
  repositoryformatversion = 0
  filemode = true
  bare = false
  logallrefupdates = true

[user]
  name = xgqfrms
  email = [email protected]
$ cat .git/config

demos

error: key does not contain a section: email
error: key does not contain a section: name

before

enter image description here

after

enter image description here

Share:
55,909

Related videos on Youtube

kawnah
Author by

kawnah

Updated on October 10, 2020

Comments

  • kawnah
    kawnah over 3 years

    I recently transferred a git repository to a new organization. I ran the following:

    git remote set-url origin https://github.com/organizationname/therepo.git

    I am successfully pulling/pushing from the new location. But now getting the following errors every time I run a git command:

    error: key does not contain a section: repositoryformatversion
    error: key does not contain a section: filemode
    error: key does not contain a section: bare
    error: key does not contain a section: logallrefupdates
    error: key does not contain a section: ignorecase
    error: key does not contain a section: precomposeunicode
    

    I initially thought it had to do with my config file however those fields are present. The first lines of My /.git/config file looks like this:

    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
    

    In this answer it suggests to check for --get-regex but I do not see any reference to that in my config or .gitconfig files. It looks like I have 2 git config files:

    /usr/local/git/etc/gitconfig

    and:

    /Users/chmd/.gitconfig

    I tried adding those keys to /Users/chmd/.gitconfig file with no such luck. What step am I missing to clear out these errors? Based on previous answer and research it seems to be my config, but I'm including those fields in my gitconfig?

  • kawnah
    kawnah almost 7 years
    Ah hah! That was it. I wasn't aware a remote change would affect that. I'll keep that in mind in the future.
  • kawnah
    kawnah almost 7 years
    I didn't have an issue with this until after. I don't really know what happened....
  • axiac
    axiac almost 7 years
    @kawnah are you sure you didn't edit .git/config by hand? It's highly improbable the file ended up this way after a correct usage of Git. Or, maybe, you are using a GUI client that doesn't use git config to handle the config file and it ruined yours.
  • kawnah
    kawnah almost 7 years
    @axiac no I would not edit that. I use atom as my text editor. Maybe it did something?
  • Khem Raj Regmi
    Khem Raj Regmi over 5 years
    @axiac can you post the all content of .git/config my config file is similar as you posted

Related