If you’ve been using Git for a while, you’ve probably come across the “Cannot add the parent directory to *safe.directory*” error. This can be frustrating, but fortunately it’s easy to fix.
In this blog post, we’ll show you how to fix this “Cannot add the parent directory to *safe.directory*” error and get your Git workflows back up and running. Stay tuned!
What is the error “Cannot add the parent directory to safe.directory in Git”?
Error “I cannot add the parent directory to *safe.directory* in Git” is recently seen on Git after upgrading to the latest version v2.35.2.windows.1. This is basically the git’s new security vulnerability because of that Cannot add the parent directory to *safe.directory error is seen.
There is nothing much you can do from your side to fix the error Cannot add the parent directory to safe.directory in Git except to have available latest version release from Git to fix the error.
Why Error Cannot add the parent directory to safe.directory in Git is Seen?
This Error “I cannot add the parent directory to *safe.directory* in Git” is seen most probably because of announcement of a vulnerability “https://github.blog/2022-04-12-git-security-vulnerability-announced/“.
As mentioned into Git document, to fix the error Cannot add the parent directory to safe.directory in Git, update the Git to the latest version Download Git 2.35.2 and it would fix the error for you.
Reason to see the error “I cannot add the parent directory to *safe.directory* in Git” is that Owner of parent directory containing the “.git” folder, that is the git repository.
How to Fix Error Cannot add the parent directory to safe.directory in Git?
Fix 1: As per Git recommendation, execute the below code for fixing the error:
git config --global --add safe.directory F:/GitHub/my-project
also try to make sure you are calling “git
” from within:
F:/GitHub/my-project
Also clone the project as a new project, just to make sure that you are the Owner.
Fix 2: From Git version v2.35.3, “Safe Directory” option can be disabled, which will immediately stop all “unsafe repository” errors.
“Safe Directory” option can be disable using below command:
git config --global --add safe.directory '*'1
Above code will make below setting changes in global .gitconfig
file:
[safe]
directory = *
Just make sure that you are not using the shared drive or shared PC before disabling the “safe.directory” option as it can post you for security risks.
How to Fix Error Cannot add the parent directory to safe.directory in Flutter on Linux”?
Execute the below code line for fixing the above error in Flutter on Linux:
git config --global --add safe.directory /opt/flutter