Issue
Sometimes during git operations (mostly when changing a git branch), the following error occurs: Error while accessing the file system. Exception caught during execution of reset command. Cannot lock /appsmith-stacks/git**
Resolution
Root Cause
This error can arise in multiple scenarios. Below are the possible causes and the recommended actions for each scenario:
- Concurrent Operations on the Same Repository
- When the same repository is being accessed by two different operations (by the same or different users), the lock prevents conflicts and corruption. In this case, wait for the other operation (as indicated in the error message) to complete before attempting the next operation.
- Do not delete the lock file in this case, as it could corrupt the ongoing operation.
- Long-running Operations (over 15 minutes)
- If an operation has been running for over 15 minutes, particularly with large applications (>5MB), the lock may persist longer than expected. Use your contextual knowledge to determine if the operation is genuinely stuck.
- If unsure, it is recommended to wait for 30 minutes to an hour. If the operation is completed during this time, the lock will automatically be released. If not, you may proceed to reset the lock manually.
-
Server Shutdown or Restart During Git Operation
- If a git operation is interrupted due to a server shutdown or restart, the lock file becomes stale and cannot be cleared automatically. In this case, manual removal of the lock is necessary.
Solution for Self-Hosted Users
To manually delete the lock file:
- Log in to your server and navigate to the directory specified in the error message (
appsmith-stacks/git-***/.git/
). - Run the following command to remove the lock file (update the path based on your error message):
rm /appsmith-stacks/git-storage/<workspace-id>/<application-id>/<application-name>/.git/index.lock
This will resolve the issue.
Advanced Cleanup
If you want to automatically check for and delete stale lock files (older than 1 day) across all repositories connected to your Appsmith instance, you can run the following command:
cd /appsmith-stacks/git-storage
find . -mindepth 5 -maxdepth 5 -type f -mtime +1 -path '*/.git/index.lock' | xargs rm
Solution for Appsmith Cloud Users
If you are facing the lock file error on Appsmith Cloud (app.appsmith.com) and it persists for more than 30 minutes, then please reach out to Appsmith Support and the team will delete the lock file for you.