can't add git submodule to repository

(Predominantly a Git question, but may be relevant to other PyroCMS users)

I have a local repository of PyroCMS – the repo is a clone of a github fork of the main project. I also have a PyroCMS module, which is also a local clone of a github fork of that project.

  • Validate if commit exists
  • Git switching between commits
  • An error was raised by libgit2. Category = 21 (MergeConflict)
  • Easy way to pull latest of all git submodules
  • How to do a GitHub pull request
  • How best to handle .classpath files in Git when developers are using different versions of JBoss in their project build paths?
  • I’ve put them both in separate directories.

    ~/Dropbox/websites/pyrocmscommunity-test/
    ~/Dropbox/github/PyroDatabase/
    

    I want to add PyroDatabase as a submodule of pyrocmscommunity-test, so I can pull updates from github, keep track of my own changes etc.

    I tried to do this by going to the top of the working tree and doing:

    git submodule add ../../github/PyroDatabase/ addons/shared_addons/modules/
    

    but it didn’t complete properly:

    Cloning into 'addons/shared_addons/modules/database'...
    ssh_exchange_identification: Connection closed by remote host
    fatal: The remote end hung up unexpectedly
    

    I don’t understand this as I didn’t specify an SSH connection, I just wanted to use the local repo. What is it trying to connect to and why?

    Also, now, whenever I repeat the command, I get this:

    'addons/shared_addons/modules' already exists in the index
    

    But I don’t understand this as there is no .gitmodules file and no mention of the modules files in .gitconfig either.

    What am I doing wrong and how do I reset things?

    Thanks,
    William

  • Repair a broken git repo - how to have a fresh start
  • How can I find the location of origin/master in git, and how do I change it?
  • Do I have to commit a merge to make git-rerere record my conflict resolution?
  • How to remove an entry with null sha1 in a Git tree
  • git erroneously states I'm ahead of origin/master by 1 commit
  • MATLAB git Pull
  • 2 Solutions collect form web for “can't add git submodule to repository”

    When specifying relative URLs for submodule location, Git takes it relatively to the origin (here Github) URL of the current projet, and not relatively to the project location on filesystem. This is because a submodule is a permanent pointer to a remote location. Here Git tries to contact the origin github repository with two levels up, which is an incorrect URL.

    As for the second error Git has created an entry in the staging area of your index, and it must be removed (unstaged) with

    git rm -r addons/shared_addons/modules
    

    Then retry with the absolute path to your clone:

    git submodule add $HOME/Dropbox/github/PyroDatabase/ addons/shared_addons/modules/
    

    Anyway adding a local clone of your project as a submodule of itself is weird, since submodules are meant to be a different repo of the containing project. Why not keep track of local and origin commits in standard Git fashion?

    What version of git are you running? You probably cannot run the command again because the directory structure you specified has been staged. You can reset things like this (be careful with this command):

    $ git status # check what has been changed
    $ git reset --hard HEAD # destroy all working copy changes
    

    A really useful way to debug what’s going on with git is to set GIT_TRACE=1. So, try running the command again once you’ve cleaned up like this:

    $ GIT_TRACE=1 git submodule add ../../github/PyroDatabase/ addons/shared_addons/modules/
    
    Git Baby is a git and github fan, let's start git clone.