N Kaushik

Fixed - A git directory for project_name is found locally with remote(s)

May 10, 2021

Git error : A git directory for project_name is found locally with remote(s)

Git submodules are added if a git project is dependent on another git project. We can add these git projects as submodules to the parent project and use features of submodules in the parent project.

A git directory for project is found locally with remotes error:

I faced this error while adding a submodule to a git project.

This issue appears sometimes while you try to add a submodule. Git provides git submodule add command for that. It looks as like below:

git submodule add git@github.com/myproject.git

If you run this command inside a git project, it will add that submodule to this project. Sometimes, it will throw one error like below:

A git directory for 'myproject' is found locally with remote(s):
  origin        git@xxxx
If you want to reuse this local git directory instead of cloning again from
  git@xxx
use the '--force' option. If the local git directory is not the correct repo
or you are unsure what this means choose another name with the '--name' option.

Solution:

The solution is simple.

  • remove the folder of the submodule.
  • remove from .gitmodules
  • rm -rf .git/modules/myproject
  • retry the above steps to add it again.

Subscribe to my Newsletter