SVN:externals equivalent in Git? SVN:externals equivalent in Git? git git

SVN:externals equivalent in Git?


Git has two approaches similar to, but not exactly equivalent to svn:externals:

  • Subtree merges insert the external project's code into a separate sub-directory within your repo. This has a detailed process to set up and then is very easy for other users, because it is automatically included when the repository is checked out or cloned. This can be a convenient way to include a dependency in your project.
    It is easy to pull changes from the other project, but complicated to submit changes back. And if the other project have to merge from your code, the project histories get merged and the two projects effectively become one.

  • Git submodules (manual) link to a particular commit in another project's repository, much like svn:externals with an -r argument. Submodules are easy to set up, but all users have to manage the submodules, which are not automatically included in checkouts (or clones).
    Although it is easy to submit changes back to the other project, doing so may cause problems if the repo has changed. Therefore it is generally not appropriate to submit changes back to a project that is under active development.


As I mention in "Git submodule new version update", you can achieve the same SVN external feature with Git 1.8.2 submodules:

git config -f .gitmodules submodule.<path>.branch <branch>

This is enough for a submodule to follow a branch (as in the LATEST commit of a remote branch of a submodule upstream repo). All you need to do is a:

git submodule update --remote

That will update the submodule.

More details are in "git submodule tracking latest".

To convert an existing submodule into one tracking a branch:see all the steps in "Git submodules: Specify a branch/tag".


I'm the author of gil (git links) tool

I have an alternative solution for the problem - gil (git links) tool

It allows to describe and manage complex git repositories dependencies.

Also it provides a solution to the git recursive submodules dependency problem.

Consider you have the following project dependencies:sample git repository dependency graph

Then you can define .gitlinks file with repositories relation description:

# ProjectsCppBenchmark CppBenchmark https://github.com/chronoxor/CppBenchmark.git masterCppCommon CppCommon https://github.com/chronoxor/CppCommon.git masterCppLogging CppLogging https://github.com/chronoxor/CppLogging.git master# ModulesCatch2 modules/Catch2 https://github.com/catchorg/Catch2.git mastercpp-optparse modules/cpp-optparse https://github.com/weisslj/cpp-optparse.git masterfmt modules/fmt https://github.com/fmtlib/fmt.git masterHdrHistogram modules/HdrHistogram https://github.com/HdrHistogram/HdrHistogram_c.git masterzlib modules/zlib https://github.com/madler/zlib.git master# Scriptsbuild scripts/build https://github.com/chronoxor/CppBuildScripts.git mastercmake scripts/cmake https://github.com/chronoxor/CppCMakeScripts.git master

Each line describe git link in the following format:

  1. Unique name of the repository
  2. Relative path of the repository (started from the path of .gitlinks file)
  3. Git repository which will be used in git clone commandRepository branch to checkout
  4. Empty line or line started with # are not parsed (treated as comment).

Finally you have to update your root sample repository:

# Clone and link all git links dependencies from .gitlinks filegil clonegil link# The same result with a single commandgil update

As the result you'll clone all required projects and link them to each other in a proper way.

If you want to commit all changes in some repository with all changes in child linked repositories you can do it with a single command:

gil commit -a -m "Some big update"

Pull, push commands works in a similar way:

gil pullgil push

Gil (git links) tool supports the following commands:

usage: gil command argumentsSupported commands:    help - show this help    context - command will show the current git link context of the current directory    clone - clone all repositories that are missed in the current context    link - link all repositories that are missed in the current context    update - clone and link in a single operation    pull - pull all repositories in the current directory    push - push all repositories in the current directory    commit - commit all repositories in the current directory

More about git recursive submodules dependency problem.