20

I'm getting this error when trying to set the global config:

$ git config --global user.name "Your Name Here"
error: could not lock config file /pathto/file/.gitconfig: No such file or directory

and the file .gitconfig is already exists, anyone have any ideas??

3
  • Do you have read/write permission on that file? (Check using ls -la /path/to/file/.gitconfig)
    – Salem
    Feb 19, 2013 at 17:13
  • -rw-rw-r-- 1 .gitconfig
    – codepros
    Feb 19, 2013 at 17:15
  • Are you running as the correct user? Which user owns .gitconfig?
    – Flimm
    Feb 19, 2013 at 17:51

8 Answers 8

22

See if any of those tips help you:

  1. Verify if there's some file called ~/.gitconfig.lock. If that's the case just delete it.

  2. The file ~/.gitconfig belongs to you (use ls -la ~/.gitconfig to check). If it does not you can change the ownership using sudo chown <your_username>:<your_username> ~/.gitconfig

If none of these solves the problem you can always edit ~/.gitconfig using your favorite text editor. It is just a INI like file. An example:

$ cat ~/.gitconfig
[user]
    name = my_username
    email = [email protected]
[core]
    editor = editor
    pager = most
[color]
    ui = auto
[merge]
    conflictstyle = diff3

I am assuming the correct location is ~/.gitconfig. If that's not the case replace it with the correct path.

Hope it helps.

3
  • there is no file named .gitconfig.lock in home directory and .gitconfig is already exists ~/
    – codepros
    Feb 19, 2013 at 17:40
  • and where is .gitconfig? In ~/.gitconfig? If that's the case then try editing it by hand.
    – Salem
    Feb 19, 2013 at 17:43
  • @Salem, I have the .gitconfig in the ~/ but still the error is there. Any advice?
    – uday
    Jan 3, 2014 at 3:22
5

In my case, there is a file .git/config.lock file in my git repo. I deleted that file and it solved the problem.

3

You need to own the directory where .gitconfig is in:

chown -R <user>.<user> /pathto/file/

That's what worked for me.

1

My problem was similar to yours. I found that the "git" user was unable to access its home directory.

I did chown -R git:git /mnt/sdb1/git and this solved the permission error.

1

My issue was that I mounted .gitconfig file in container from my local filesystem. It seems that way git stores gitconfig is by moving files around. It can not commit, because it can not move (not just write, but mv) temporary file into ~/.gitconfig . My solution was to mount directory (home directory) and not just .gitconfig file.

0

For my case, my ~/.gitconfig file was pointing(symlinked) to my old dotfiles, which I had moved to a different location, meaning the gitconfig was pointing to an inexistent file.

To know where my gitconfig was symlinked to, I did ls -la ~/.gitconfig, which showed that it was pointing to a file I had moved elsewhere.

I had to update the symbolic link to my new dotfiles (dotfiles is just a folder name of all my .smth files).

To update the symlink, I did ln -sf ~/your-new/path-to/gitconfig.symlink ~/.gitconfig

Everything then worked well

0

In my case the error was:

error: could not lock config file .git/config: No such file or directory

I solved it by creating the .git directory:

mkdir -p ~/.git
0

In my case I had to remove File config.lock inside my git repository .git/ folder.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .