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 directoryand the file .gitconfig is already exists, anyone have any ideas??
38 Answers
See if any of those tips help you:
Verify if there's some file called
~/.gitconfig.lock. If that's the case just delete it.The file
~/.gitconfigbelongs to you (usels -la ~/.gitconfigto check). If it does not you can change the ownership usingsudo 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 =
[core] editor = editor pager = most
[color] ui = auto
[merge] conflictstyle = diff3I am assuming the correct location is ~/.gitconfig. If that's not the case replace it with the correct path.
Hope it helps.
3In my case, there is a file .git/config.lock file in my git repo. I deleted that file and it solved the problem.
You need to own the directory where .gitconfig is in:
chown -R <user>.<user> /pathto/file/That's what worked for me.
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.
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
In my case the error was:
error: could not lock config file .git/config: No such file or directoryI solved it by creating the .git directory:
mkdir -p ~/.git In my case I had to remove File config.lock inside my git repository .git/ folder.
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.