Git push fails with "error: could not lock config file"
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
The purpose of this article is to detail why this issue occurs and provide troubleshooting steps to resolve the issue.
Environment
Performing a GIT push to a repository hosted in Bitbucket Cloud
Diagnosis
When attempting to push to a GIT repository, you encounter some variant of the following error message, and the push is blocked as a result:
1
2
error: could not lock config file ~/.git/config: No such file or directory
fatal: could not set 'core.repositoryformatversion' to '0'
Cause
The config.lock file is a temporary file used to protect your GIT config during the process of updating the repository’s configuration settings. It is created to ensure that no other process or users can make concurrent changes to the file, which could lead to conflicts or corruption.
If there is an existing process already running that has not yet been terminated, the config.lock file will remain - this prevents further processes from executing as the file can't be created again by the new process (as it already exists)
Solution
Firstly, you will need to check to see if the config.lock file already exists - you can do so by making note of the directory that is reported in the error message and navigating to it/manually deleting it, or performing file check/deletion commands in a terminal:
1 2 3 4 5 6
# Navigate to the folder path in the error message cd /path/.git/ # Check the list of files in this folder for a lock file ls # Delete the lock file (if present) rm config.lock
Attempt to perform a GIT push again once the file is deleted
If you can't delete the file, or you still can't GIT push - you can try checking for any currently running git processes:
1 2 3 4 5
# Linux/Mac OS check process ps aux | grep git # Windows OS check process tasklist | findstr git
Once you have located the processID (found in the second column), you can terminate these process(es):
NOTE - You must replace the placeholder number 123 in the commands below with the processID found in the second column of the output generated from Step 3
1 2 3 4 5
# Linux/Mac OS kill process kill 123 # Windows OS kill process taskkill /PID 123 /F
Check for the lock file again (Step 1) and delete it if present, then attempt to perform a GIT push once the file is deleted
NOTE: If all else fails, you can also reboot your machine to kill all running processes and ensure that the config.lock file is removed as a result
If you are unable to resolve the issue after following this documentation - please raisea support ticket or a community support ticket for further assistance.
Was this helpful?