frankV
frankV

Reputation: 5513

Issues With Git Submodules

I'm trying to add files to a git repo that were somehow previously added as a submodule. I don't know how that happened.

I cannot find a .gitmodules file anywhere and my .git/config looks like this:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = [email protected]:frankV/dotfiles.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

I need to include the directory for vim vundle but I can't due to the issues stated above. To this point I have been unable to remove it from this repo or add any files below the directory for vundle.

When I try to add a file I get: fatal: Path '_vim/bundle/vundle/autoload/vundle' is in submodule '_vim/bundle/vundle'

and my git status output:

...
#   modified:   _vim/bundle/Command-T (untracked content)
#   modified:   _vim/bundle/The-NERD-Commenter (untracked content)
#   modified:   _vim/bundle/The-NERD-tree (untracked content)
#   modified:   _vim/bundle/matchit.zip (untracked content)
...

As you can see vundle is not in this list and it's fine to not track these submodules as they install via vundle... all the more reason however to get vundle working!

Upvotes: 1

Views: 949

Answers (1)

jthill
jthill

Reputation: 60235

You have a nested repository, find it with find . -name .git, if you really want to import historyless source you can then git rm its containing directory and remove the .git directory itself. To not lose current history you could fetch from it and subtree-merge the branches, but the sweet spot in terms of preserving structure and history with minimum effort is going to be just keeping the repo structure as it is.

Git calls nested repositories submodules, and does have a command to help you manage the gruntwork --- for instance, submodules' primary repos are often hosted by third parties (yours at git://github.com/gmarik/vundle.git for instance), so the submodule command sets up some infrastructure to help advertise where any of your repo's clients can find the submodules' primaries --- but everything the submodule command does is assistance with mundane tasks like that. No other git command has any clue whether a repo is being used as a submodule or not, because it doesn't have to care.

So what it appears you're doing is trying to use the results of someone else's ongoing project as a building block in your own project, and the git way to do that is do simply do it in the most direct way possible: clone their project and use it as part of your own. This other answer I wrote might be TMI, it's about splitting a project into submodules, but it is another take on just how simple and direct the concept is.

Upvotes: 2

Related Questions