12

While trying to set up Git with my GitHub account the following error keeps persisting whenever I try to do a global config.

It works fine for repositories, but the global doesn't work.

Here's how it shows:

$ git config --global user.name "username"
error: could not lock config file C:/Path/to/.gitconfig: File exists

I'm using Git 2.21.0 on Windows 10 Pro.

double-beep
  • 5,031
  • 17
  • 33
  • 41
tatzooism
  • 121
  • 1
  • 1
  • 3
  • That error might mean that the file is already locked for editing by another process. There are several ways to find and kill the process that has it locked, but the easiest solution is a reboot. It might also be a permissions error, in that git has read-only access to the file and thus can neither edit nor replace it. – JDB Mar 24 '19 at 19:26
  • 1
    Possible duplicate of [Trouble setting up git with my GitHub Account error: could not lock config file](https://stackoverflow.com/questions/14959972/trouble-setting-up-git-with-my-github-account-error-could-not-lock-config-file) – phd Mar 24 '19 at 21:08
  • https://stackoverflow.com/search?q=%5Bgit%5D+error%3A+could+not+lock+config+file+.gitconfig+File+exists – phd Mar 24 '19 at 21:08

3 Answers3

10

Since you're on Windows 10, it could be an issue if your .gitconfig is located at C:. If that's the case, try running your git bash with Administrator privileges (right-click on your executable, select More > run as Administrator) and see if that works. You need administrator privileges to work on files at the root of C:. That worked for me.

rup
  • 123
  • 1
  • 10
  • At least now, 3 years later, I can add the following: If the error says "File exists" then there's no permission problem. In that case, just delete the gitconfig.lock file. If the error says "Permission denied", then use an elevated command prompt. – Bastian Springer Aug 08 '23 at 10:17
8

Check your folder where the .gitconfig file is located, and if there is a .gitconfig.lock file, delete it. I got the same error and this fixed it for me.

0

In other situation, If you don't have .gitconfig.lock file, there should be a config.lock file in .git folder of the repo. You can delete this file and It will fixed this problem.