Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using someone else's repo as a Git Submodule on GitHub

I am trying to find out if it is possible to use someone else's repository (or branch of a repository) as a Submodule in your own Git repository. Documentation on github itself is either missing, or I'm not using the right terminology to look for it. If this isn't the preferred way to go about including a public repository as a shared library within ones git project, suggestions as an alternative best practice would be appreciated.

like image 330
Graham Conzett Avatar asked Mar 09 '11 21:03

Graham Conzett


People also ask

How do I create a submodule from an existing repo?

In order to add a Git submodule, use the “git submodule add” command and specify the URL of the Git remote repository to be included as a submodule. When adding a Git submodule, your submodule will be staged. As a consequence, you will need to commit your submodule by using the “git commit” command.

Can I clone someone else's repository?

On GitHub you can visit somebody else's repository and fork that repository. This will make an entire independent copy of that person's repository in your account (where you have permission to modify your copy), and GitHub will remember where your copy came from. In this case the copy is known as a fork .


1 Answers

Yes, you can add any repository as a submodule in your project. Just do:

git submodule add git://github.com/whomsoever/whatever.git 

... in the top level of your repository. This is indeed the easiest way with git to use some existing useful repository within your own. For more information on submodules, you could look at:

  • Pro Git's section on submodules
  • The quite readable bit in the git manual
  • The section on submodules in the git community book

Update: as jfountain points out below, if you want to add the submodule at a subdirectory path (or with a name different from the default) you can supply that as an additional parameter to that command, e.g.:

git submodule add git://github.com/whomsoever/whatever.git foo/bar 
like image 63
Mark Longair Avatar answered Sep 26 '22 11:09

Mark Longair