Error with git: “ already exists and is not a valid git repo”

It is seying that I cannot do this:

 git submodule add -f git@github.com:thephpleague/oauth2-server.git libs/OAuth/functions

Because of this:

  • Git stash pop wants to merge
  • Why does git commit after a merge by default?
  • How to maintain code review history in Stash pull requests
  • Symfony2 - creating own vendor bundle - project and git strategy
  • Git says I deleted photos that I put inside a new folder?
  • android studio delete file from vcs
  • ‘libs/OAuth/functions’ already exists and is not a valid git repo

    I just don’t get it. It does not exists anywhere. Is there another git config file hidden on my computer that I don’t know of or something? I tried deleting .git and pulling everything again that did not do anything. Any ideas?

    I also tried this:

    git ls-files --stage functions
    

    When I was inside of libs/OAuth and I got nothing.

    Then I tried this:

    sudo git rm --cached functions
    

    I got this error:

    fatal: pathspec 'functions' did not match any files
    

    I also tried this:

    sudo git rm -r --cached functions
    

    And got the same previous error.

  • How to avoid exposing secret informations in vimrc when pushing it to Github
  • Cruise Control.NET: how to set username and password for git repository task?
  • Move commits from linear history to a separate branch
  • Retrieve a single file from a repository
  • Set user name in every commit
  • Calling git from R
  • 2 Solutions collect form web for “Error with git: “ already exists and is not a valid git repo””

    Even if the folder doesn’t exist, check the index status:

    cd libs/OAuth
    git ls-files -- functions
    

    If there is an entry registered in the index, you will need to remove it before being able to add your subrepos as a submodule.
    (as explained in “Issue with adding common code as git submodule: “already exists in the index””)

    All this assumes that you are at the root folder of a currently cloned repo, which will act as the parent repo of any submodule you would declare.

    In case someone else had a similar case as mine and was struggling with this as I was because of a stupid reason:

    Check if for any reason the file doesn’t already exists (I had a failed git subomdule add previously)

    So in the context of the question rm the file:


    rm -rf libs/OAuth/functions

    And then try to re add

    Git Baby is a git and github fan, let's start git clone.