Trouble setting up git with my GitHub Account error: could not lock config file
GitGit Problem Overview
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??
Git Solutions
Solution 1 - Git
A bit like in "Trouble setting up Tower with my GitHub Account - error: could not lock config file", check how that ~/.gitconfig
file has been created.
Ie: with which rights associated to it?
Make also sure your $HOME
variable is correctly set when you are executing the git config --global
command.
Solution 2 - Git
Check if you have a .git directory in your home folder and if you don't:
mkdir ~/.git
Solved the problem in my case.
Solution 3 - Git
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)
Solution 4 - Git
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
Solution 5 - Git
just do Run as Administrator.......you need to run the program in the run as administrator mode in windows
Solution 6 - Git
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.
Solution 7 - Git
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.
Solution 8 - Git
Just use the following command if you wanna set configuration in system level:
$ sudo git config --system user.name "my_name"
Solution 9 - Git
I rename the .gitconfig file as xyz.gitconfig, then git will generate a new .gitconfig file, that wokrd
Solution 10 - Git
Update you Git client plugin. It worked for me =) https://issues.jenkins-ci.org/browse/JENKINS-21016
Solution 11 - Git
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.
Solution 12 - Git
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
Solution 13 - Git
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
Solution 14 - Git
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.
Solution 15 - Git
You can also try issuing the command while in your home directory.
Solution 16 - Git
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".
Solution 17 - Git
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
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.
Solution 18 - Git
This is what worked for me,
- open Start Menu
- type "environment" without quotes
- choose edit environment variables (system or user, any)
- under the user variables, select HOME
- click edit
- add the missing % prefix of %USERPROFILE%
- keep clicking OK for all open windows
[]
Solution 19 - Git
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".
Solution 20 - Git
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
Solution 21 - Git
I faced the same problem and tried several solutions provided here and here is what works for me
Deleting both .gitconfig
and .gitconfig.lock
files and then run the setting of the global config again fix that for me, just run this in order
rm -rf ~/.gitconfig.lock ~/.gitconfig
then
git config --global user.name "YOUR NAME"