tags:

views:

704

answers:

4

Solved Problem: to show external code dependency by submodules: Thanks to VonC!

Current Problem: to have a submodule without duplicate contents in two folders

A temporary solution to the current problem: to change the name of the folder to bin-github, since the name of the folder as a submodule is bin. This means I need to duplicate contents at my Home.

My HOME folder is dependent on ~/bin. I have files located at HOME at the repository Masi, while at ~/bin at the repo bin at Github. My relevant folder structure at Home:

~
|-- [drwxr-xr-x] bin
    | -- fileA
    ` -- folderA
    ...

I would like to know how to show make ~/bin a submodule of the Git at Masi.

How can you make ~/bin a submodule of my Git at ~/ ?

+4  A: 

First, do not forget that with Git, you can not "add" a directory, only the content of at least one file within that directory.

Then you have two choices:

  • submodules, in order for Masi to refer a specific commit of your [files within a] bin directory stored at GitHub (or to the latest commit of a branch, stored at GitHub)

  • subtree merge, in order to mix the two repositories together and more easily follow modifications to files within bin directly from the Masi repository. That may be simpler in your scenario.

See this answer for more on those 2 strategies.


On the submodules path, declaring the submodule is only half the work. You still have to initialize your submodule the first time by

git submodule git init

You need then pull your submodules:

git submodule foreach git pull

and then update your submodule

git submodule update

See also this practical example.

VonC
Please, see my reply below.
Masi
@ Please, see 2nd reply to your answer.
Masi
@ Please, see my reply to your comment below.
Masi
I opened a new thread based on your answer at http://stackoverflow.com/questions/1155095/unable-to-git-submodule-foreach-git-pull
Masi
A: 

Reply to VonC's answer:

I run

git submodule add git://github.com/masi/bin.git bin-github-copy

because I cannot add a new repo with the same name as my existing folder bin.

My .gitmodules is

[submodule "bin-github-copy"]
    path = bin-github-copy
    url = git://github.com/masi/bin.git

I run

git clone git://github.com/masi/Sam.git

I get an emty bin -directory.

How can I get the content of bin?

Masi
you need to pull the update your submodule. I have amended my answer. I will check again this question in 7 to 10 hours.
VonC
This question is solved.
Masi
A: 

#2 Reply to VonC's answer:

I changed my .gitmodules to the following such that I do not have a duplicate copy of it in my home.

[submodule "bin"]
    path = bin
    url = git://github.com/masi/bin.git

This seems to be a different situation as I cannot pull the submodule-bin -folder similarly as above.

I get the following now at a fresh-cloned git-repo

Sam master $ git submodule git init
error: pathspec 'git' did not match any file(s) known to git.
error: pathspec 'init' did not match any file(s) known to git.
Did you forget to 'git add'?                          # I am not sure what this means
Sam master $ git submodule foreach git pull
Sam master $ git submodule update

I have the external repository in my .gitmodules. Why is it asking me to git add?

Masi
"git submodule git add"? it should have been "git submodule add". I believe the http://daniel.collectiveidea.com/blog/2008/4/9/git-submodules article is quite informative on that topic.
VonC
@Please, see my reply to your comment at http://stackoverflow.com/questions/1145422/to-show-external-folder-dependency-in-git/1147178#1147178
Masi
@VonC: The part which you commented was my deduction about the error message. Please, see my edit.
Masi
A: 

#3 Reply to VonC's comment:

My .gitmodules

[submodule "bin"]   
         path = bin
         url = git://github.com/masi/bin.git

I feel that I do not need to add anymore the submodule again, since I have it in my .gitmodules.

I run

Sam master $ git submodule update
Sam master $ git submodule foreach git pull
Sam master $ ls bin
Masi