Bryan Bryan - 3 months ago 18
Git Question

Git add Folder with Existing Git Repository

I am making a git repository for my MacVim installation. Some of the plugins in my repository have their own .git folders and repo. The problem is... when I try to add one of these folders to my main repository, it does nothing.

My guess:

I can't add the folder because it is a git repo on it's own. I must add as a submodule or remove the .git folder.

How do I add my sub repos as a submodule?

bryan-mini:.vim bsaltzman$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
# (commit or discard the untracked or modified content in submodules)
#
# modified: bundle/YouCompleteMe (modified content)
# modified: bundle/nerdtree (modified content)
# modified: bundle/ultisnips (modified content)
#
no changes added to commit (use "git add" and/or "git commit -a")

// This
bryan-mini:.vim bsaltzman$ git add bundle/YouCompleteMe/
// OR THIS
bryan-mini:.vim bsaltzman$ git submodule add bundle/YouCompleteMe/
repo URL: 'bundle/YouCompleteMe/' must be absolute or begin with ./|../

bryan-mini:.vim bsaltzman$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
# (commit or discard the untracked or modified content in submodules)
#
# modified: bundle/YouCompleteMe (modified content)
# modified: bundle/nerdtree (modified content)
# modified: bundle/ultisnips (modified content)
#
no changes added to commit (use "git add" and/or "git commit -a")

Answer

It looks like you might have correctly added those repos as submodules but you've changed/added/deleted a file inside those repos. If you cd into bundle/nerdtree and do a 'git status' it should tell you what is different. If you get the submodule back into a clean state the top-level one should stop saying "modified content"

Also, your command:

git submodule add bundle/YouCompleteMe/

is incorrect. 'git submodule add' takes a repo url like so:

git submodule add https://github.com/Valloric/YouCompleteMe.git

But from your output it looks like you've already done that correctly at some point. You appear to be using Pathogen to manage your submodules - the docs for it should walk you through this process pretty well. Or you could switch to Vundle which apparently has some advantages (personally I'm still on Pathogen).