2

Currently I am trying to clone this git repo: https://github.com/twilio/OpenVBX into my main repo, as though it was a directory. The issue lies, in it that when I try to commit the main repo with git add ., nothing in the sub dir (submodule) gets committed, and when I try to git add path/to/file it gives me the fatal error: 'Path "" is in submodule'. It seems git is not tracking the sub directory, nor does it notice that it and its files exist at all.

I looked around and came upon this thread: Unable to track files within Git submodules, however, the fix in it has not seemed to work with me or my limited knowledge of git. I do not have any .gitmodules file in my main, and the .git dir I have is not relevant as far I can tell. Is there a way I can make it so its not a submodule anymore? Is there someway I can delete it, and readd it without its git backbone?

I'm more than lost right now, thanks in advance for your help!

Community
  • 1
  • 1
willium
  • 2,048
  • 5
  • 25
  • 34

3 Answers3

4

If you want to keep history and the ability to pull subsequent changes, you can use git subtree merge strategy:

git remote add -f OpenVBX git://github.com/twilio/OpenVBX.git
git merge -s ours --no-commit OpenVBX/master
git read-tree --prefix=OpenVBX/ -u OpenVBX/master
git commit -m "Merge OpenVBX in subdirectory"

And when you want to pull OpenVBX:

git pull -s subtree OpenVBX master
Michaël Witrant
  • 7,525
  • 40
  • 44
  • 1
    Checkout http://progit.org/book/ch6-7.html for additional info on Subtree Merging and chapter 6.7: http://progit.org/book/ch6-7.htm for info on submodules. – Bob Fanger Jun 05 '11 at 12:52
2

If you want to clone OpenVBX into your repository and don't care about its prior history, do the following:

rm -rf OpenVBX
git clone https://github.com/twilio/OpenVBX.git
rm -rf OpenVBX/.git
git add OpenVBX
git commit -m "Import OpenVBX version x.y"

The key point is the rm -rf OpenVBX/.git which removes the .git repository information from OpenVBX. The rest of it is adding and committing files as normal.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
2

As far as I understand it, I think your issue is that you haven't grokked submodules correctly. There are two scenarios here:

1) You want to use the OpenVBX repository as a module in your repo, but you have no intention of changing the code in the OpenVBX repository itself, that is, you are going to use the library 'as is' without modifying it. In this case, all you need to do is:

git submodule add git://github.com/twilio/OpenVBX.git plugins/OpenVBX

where plugins/OpenVBX is the path where you wish to add it in your own repository. For example, I carried out these steps on my setup and here is how it looks:

~/Personal$ mkdir test
~/Personal$ cd test/
~/Personal/test$ echo "Test repo for playing around with submodules" > README
~/Personal/test$ mkdir plugins
~/Personal/test$ echo "I'll keep my plugins here" > plugins/README
~/Personal/test$ git init
Initialized empty Git repository in /home/vedang/Personal/test/.git/
~/Personal/test$ git add .
~/Personal/test$ git commit -m "Initial commit"
[master (root-commit) 4539047] Initial commit
 2 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644 README
 create mode 100644 plugins/README
~/Personal/test$ git submodule add git://github.com/twilio/OpenVBX.git plugins/OpenVBX
Initialized empty Git repository in /home/vedang/Personal/test/plugins/OpenVBX/.git/
remote: Counting objects: 2055, done.
remote: Compressing objects: 100% (1315/1315), done.
remote: Total 2055 (delta 1132), reused 1430 (delta 695)
Receiving objects: 100% (2055/2055), 4.96 MiB | 25 KiB/s, done.
Resolving deltas: 100% (1132/1132), done.
~/Personal/test$ git add .gitmodules
~/Personal/test$ git add plugins/OpenVBX
~/Personal/test$ git commit -m "Added openvbx as a submodule"
[master 5318022] Added openvbx as a submodule
 2 files changed, 4 insertions(+), 0 deletions(-)
 create mode 100644 .gitmodules
 create mode 160000 plugins/OpenVBX
~/Personal/test$ git log -p
commit 5318022936429a34cabddfeedc3574f7744127c3
Author: Vedang Manerikar 
Date:   Sun Jun 5 16:04:11 2011 +0530

Added openvbx as a submodule

diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..bbde679 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "plugins/OpenVBX"] + path = plugins/OpenVBX + url = git://github.com/twilio/OpenVBX.git diff --git a/plugins/OpenVBX b/plugins/OpenVBX new file mode 160000 index 0000000..ade10d8 --- /dev/null +++ b/plugins/OpenVBX @@ -0,0 +1 @@ +Subproject commit ade10d86fd9556e840f337c255037c163facd2a3

As you can see, for git, a submodule is just a commit-id pointing to some SHA in some other repository. It does not care about the structure of your submodule directory.

2) If you want to modify code in the submodule as well, the only major difference is that you should have write permissions to the repository you are adding as a submodule. On github, this is as simple as forking the parent repository and using your forked repo as the submodule. In this case too, git will treat your submodule as just a SHA in the main repository. However if you do a git status inside the submodule directory (plugins/OpenVBX in our case), you'll be able to commit your changes there and push them to the submodule repository.

Using submodules has some advantages over simply copying the source code into your repository. The main advantage is that you can stay up-to-date with the original library and benefit from additional code and bug-fixes. I recommend you try to use submodules one more time before you give up on them.

vedang
  • 3,111
  • 2
  • 24
  • 33