[git] Trouble setting up git with my GitHub Account error: could not lock config file

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??

This question is related to git

The answer is


I have "experienced" this error on Windows because my name (and hence %HOMEPATH%) contains a non ascii character (é). Either git or cmd.exe or anything else could not cope with this.


This is an old post, but I had this issue recently, but I solved the issue differently from everyone else here. I received the same error because I did not have permission to the $HOME path on my computer. Simply by accessing the folder via double-clicking through the folders in your files, I was prompted with boxes saying that I would gain permanent access to these folders after entering through them for the first time. After I accessed the deepest folder in my $HOME variable, the command worked.


This could be caused by the presence of ~/.gitconfig.lock It's possible this file could be an artifact of a previously running git that was aborted for some reason, e.g. ansible timed out or ^C


So I know this thread is Old, but I had the same issue and fixed it. Hopefully this works for someone else.

When i tried using "sudo" or anything in powershell/cmd it was an unrecognized command. So i reinstalled git for windows, during the install it failed and pointed me to C:/ProgramFiles/git/etc/gitconfig I deleted that file, and reinstalled. Same Error when saving credentials, So i moved the newly created gitconfig from programfiles, to my HomePath location C:/Users/Name

Now I can save credentials under file-->Options-->git Finally, I can commit/push on githubdesktop


Just use the following command if you wanna set configuration in system level:

$ sudo git config --system user.name "my_name"

I am old to the party but may be this will help some one. Thanks to @paperclip

In Windows 10:

Step 1: Go to This PC > Right click Properties

step 2: Click Advanced System Settings and click Environment Variables

Step 3: Under System Variables create new variable called HOME and input the value as %USERPROFILE% like below

enter image description here

Step 4: Important You must restart your PC to take effect

Step 5: Install Git for Windows now and optional Tortoise Git for windows if you prefer.

Make a git clone request or try pushing something in to your repo. Magic it will work. All should work fine now.


Update you Git client plugin. It worked for me =) https://issues.jenkins-ci.org/browse/JENKINS-21016


Check if you have a .git directory in your home folder and if you don't:

mkdir ~/.git

Solved the problem in my case.


I rename the .gitconfig file as xyz.gitconfig, then git will generate a new .gitconfig file, that wokrd


I've gotten this error when a lock file exists for gitconfig. Try and find and remove .gitconfig.lock (on my linux box it was in my home dir)


I started getting this error after windows upgrade. My Home variable somehow removed after windows upgrade. Issue resolved by adding HOME variable as "C"\Users\myusername".


just do Run as Administrator.......you need to run the program in the run as administrator mode in windows


For me, the problem was not git config, but .git directory at my current repo was created by root and I was trying to do something with my other user. I changed the perm


In my case, the .git/config file was created not in my $HOME directory, but inside my repository on .git/config.lock

Deleting the file fixed the problem. The file is created, when I switch branches with git checkout -f branchname and files from a recently created submodule were overwritten by git checkout.

$ git branch --set-upstream-to=origin/branchname
error: could not lock config file .git/config: File exists
error: Unable to write upstream branch configuration
hint: 
hint: After fixing the error cause you may try to fix up
hint: the remote tracking information by invoking
hint: "git branch --set-upstream-to=origin/branchname".

You can also try issuing the command while in your home directory.


This will happen, if the user home directory is not writable by the user. git config --global needs to create a "lock" file (~/.gitconfig.lock) in user home directory.

Check the permissions and try to create one.

# cat ~/.gitconfig.lock
cat: /home/users/developer/.gitconfig.lock: No such file or directory
# touch ~/.gitconfig.lock

## Now check, if a file has been created?
# cat ~/.gitconfig.lock
#

NOTE: If it succeeds, You must delete this file, otherwise git will throw another error!

If a user has no permission of creating this file, You must check and change permissions for the home directory.


Windows Users: Ensure your Environment Variables are correctly setup.

I had the following for my account username 'paperclip':

My Computer (right-click) > Properties > Advanced (tab) > Environment Variables (under System Variables):

HOME -> %HOMEPATH%

HOMEPATH -> C:\Documents and Settings\paperclip

It seems like Git could not resolve / expand %HOME% to %HOMEPATH% as you would it expect it to. Instead I needed to make %HOME% the same as %HOMEPATH% by changing it to:

HOME -> C:\Documents and Settings\paperclip


In Windows: Right click on "Git Bash" icon -> Run as Administrator. it helped me.

Git tries to create a config file on disk C:/ but it has no permission to do that.