Reputation: 908
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??
Upvotes: 76
Views: 213115
Reputation: 311
For someone who might have an issue similar to mine.
I also got error: could not lock config file /builds/group1/project1/.gitconfig: No such file or directory
My issue was because of (below) in the gitlab ci file
variables:
HOME: $CI_PROJECT_DIR
From a quick search on why, it seems git uses the variable HOME and by 're-declaring' it I was kinda "overriding it"
Solution:
Redefined HOME
to HOME_WORKSPACE_DIR
| Error was solved after that
Upvotes: 0
Reputation: 1
Just go environment variables from search box. And remove "home" from both system variables and user variables. Restart cmd and do it again. It will work.
Upvotes: 0
Reputation: 1
You just go to the main folder of your repository and use the commands:
git config user.name "UserName"
git config user.email "[email protected]"
This worked for me.
Upvotes: 0
Reputation: 41
This is what worked for me,
[]
Upvotes: 3
Reputation: 1188
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"
Upvotes: 0
Reputation: 4417
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.
Upvotes: 2
Reputation:
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
Upvotes: 0
Reputation: 79
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".
Upvotes: 0
Reputation: 190
I rename the .gitconfig file as xyz.gitconfig, then git will generate a new .gitconfig file, that wokrd
Upvotes: 3
Reputation: 1045
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.
Upvotes: 7
Reputation: 9485
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".
Upvotes: 2
Reputation: 13463
You can also try issuing the command while in your home directory.
Upvotes: 1
Reputation: 490
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.
Upvotes: 1
Reputation: 31
Just use the following command if you wanna set configuration in system level:
$ sudo git config --system user.name "my_name"
Upvotes: 3
Reputation: 184
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
Upvotes: 2
Reputation: 171
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.
Upvotes: 16
Reputation: 1146
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
Upvotes: 1
Reputation: 451
Check if you have a .git directory in your home folder and if you don't:
mkdir ~/.git
Solved the problem in my case.
Upvotes: 26
Reputation: 311
just do Run as Administrator.......you need to run the program in the run as administrator mode in windows
Upvotes: 31
Reputation: 40613
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.
Upvotes: 2
Reputation: 2330
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
Upvotes: 22
Reputation: 4955
Update you Git client plugin. It worked for me =) https://issues.jenkins-ci.org/browse/JENKINS-21016
Upvotes: 2
Reputation: 3008
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)
Upvotes: 25
Reputation: 1330072
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.
Upvotes: 42