views:

59

answers:

2

I have a local git repository a "central" repo at github. I'm working on a part of a project, while a friend is working on a related piece that is in an entirely separate repo, is it possible for me to simply link directly to my friend's repo?

For example, the app is called widgets. I have all my code in widgets/app/mycode and my friend is writing code that goes into widgets/plugins/awesome/hiscode.

I want to be able to always have http://github.com/mycode/widgets/plugins/hiscode to be a direct link or clone to http://github.com/hiscode/awesome?

It could be possible I'm missing something basic in my question or knowledge of git, if so please ask, and I'll be happy to try to fill in the blanks.

I am deploying to my production site via capistrano, so maybe a script of some kind may be easier?? I don't know (that's why I'm posting)!!

+1  A: 

It sounds like submodules would be a good solution. I'm not 100% certain on the github url, but this should get you close:

git submodule add http://github.com/hiscode/awesome plugins/hiscode

To update the submodule and make sure you can still commit to the "awesome plugin", you'll execute the following from your repoisitory's root:

git submodule update
cd plugins/hiscode
git checkout master

Note that you're essentially nesting git repositories at this point, not ACTUALLY making one part of another.

For SVN users: This is similar to subversion's svn:externals property with a specific revision number. Executing the above script is the same as updating the revision number in the svn property.

mattdekrey
+1  A: 

As mentioned in git submodules, true nature, this is possible by declaring in widgets/plugins/awesome/hiscode a submodule referring to http://github.com/hiscode/awesome.

You can then regularly pull from that submodule his latest changes in order to update it, provided you then commit again from the widgets/ directory (which is your "main" project, that is the project which contains the submodule).
That way your main project will record the new SHA1 of the updated submodules.

You can even directly develop in that submodule, pushing directly to http://github.com/mycode/widgets/plugins/hiscode (while still committing widget, again to record the new SHA1).
But you need to remember to checkout a branch first within that submodule, because a "submodule update" always initialize/update it as a detached head.

VonC
with this solution will I have to pull the submodule before commiting to my main repo every time to make sure I have the most recent changes? If so is there any way of doing this automatically?
ThinkBohemian
@ThinkBohemian: If your most recent change (to that submodule) has been made outside the main project, then yes, a pull within the submodule is needed before the main project commit. But (like detailed in "submodule, true nature"), you can also make a modification directly within the submodule.
VonC