Questions tagged [git-submodules]

Submodules allow you to keep a Git repository as a subdirectory of another Git repository.

A submodule allows you to keep a Git repository as a subdirectory of another Git repository. This lets you clone another repository into your project and keep your commits separate. [Pro Git book]

The parent repo keep track of a submodule in:

  • a .gitmodules file (for the url of the sub repo)
  • a special entry in its index, called gitlink for the commit hash at which the submodule is checked out (a submodule is always initialized in a detached HEAD mode)

Common questions:

3102 questions
97
votes
4 answers

Force Git submodules to always stay current

I love git submodules. Also, I hate git submodules. What I love about them is how it enables to you to cleanly compartmentalize dependencies etc. I get the point of having them point to a specific commit on a repo, I do. But in my case, I'm…
Ben
  • 16,124
  • 22
  • 77
  • 122
93
votes
9 answers

Git submodules not updating in Jenkins build

I have a submodule in a project in Jenkins. I've enabled the advanced setting to recursively update submodules. When I run the build, I see that the workspace has the files from the submodule. The problem is, it seems to be the first revision of the…
Ben
  • 16,124
  • 22
  • 77
  • 122
93
votes
3 answers

Why is git submodule not updated automatically on git checkout?

When switching branches with git checkout I would assume that most of the time you would want to update your submodules. In what situation do you not want to update submodules after switching? What would break if this was done automatically by git…
serbaut
  • 5,852
  • 2
  • 28
  • 32
92
votes
6 answers

Ignore new commits for git submodule

Background Using Git 1.8.1.1 on Linux. The repository looks as follows: master book The submodule was created as follows: $ cd /path/to/master $ git submodule add https://user@bitbucket.org/user/repo.git book The book submodule is clean: $ cd…
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
91
votes
7 answers

Git Submodules. Pulling into a new clone of the super-project

OK. So I thought I had this licked ... but now .... I have a project which includes one small library from GitHub as a submodule. In the original version of that super-project the submodule is working as expected. However, I just cloned the…
interstar
  • 26,048
  • 36
  • 112
  • 180
90
votes
4 answers

How to make an existing directory within a git repository a git submodule

I'm very confused about git-submodules. Basically my problem is that I can't make git understand that ~/main-project/submodule is a submodule. I have good experience with git submodules: in my dotfiles repository I created the .gitmodules file in…
Doron Behar
  • 2,606
  • 2
  • 21
  • 24
81
votes
4 answers

Retrospectively add --recursive to a git repo

If you git clone with --recursive, you can get all the git submodules too. If I've forgotten to add this magical flag when cloning, as can happen, how do I now go and get any submodules? Additionally, how can I set the recursive flag as a default…
kenneth
  • 1,093
  • 1
  • 8
  • 10
79
votes
1 answer

Linking a single file from another git repository

How do you link a single file from another git repository to your own repository? I don't want the full repository, just a single file. Using git submodule seems like the right route to go, but it wants to grab the whole thing.
SineSwiper
  • 2,046
  • 2
  • 18
  • 22
79
votes
6 answers

Git submodules and ssh access

I have some trouble with a git repository that contains several submodules. The super git repository was constructed with the commands mkdir projectname cd projectname git init git submodule add ssh://myusername@server/pathtorepos When a different…
midtiby
  • 14,550
  • 6
  • 34
  • 43
79
votes
10 answers

Why does git fail to fetch specific valid submodule for a given commit and how to fix it?

I have a git repo which has another one as a submodule dependency. In the root of my project (where the .git, .gitsubmodules etc. are) I called git submodule update This failed with the following message: Fetched in submodule path 'src/framework',…
rbaleksandar
  • 8,713
  • 7
  • 76
  • 161
76
votes
2 answers

git submodule update vs git submodule sync

The git documentation doesn't make it at all clear what the difference is between a git submodule update and a git submodule sync is. I'm also not finding any help out on the web. Can someone help me out with what the difference is here? update …
Benjamin Leinweber
  • 2,774
  • 1
  • 24
  • 41
73
votes
7 answers

Git commit to common submodule (master branch)

I've two or more projects (let's call them ProjectFoo and ProjectBar) having some common code that I put in a submodule. My understanding is that if I commit changes to a submodule from within ProjectFoo it'll be in a detached head that only all…
Wernight
  • 36,122
  • 25
  • 118
  • 131
73
votes
1 answer

How do I add files in Git to the path of a former submodule?

I have a project that used to contain a submodule, at path mysubmodule. I installed the latest Git from source (1.8.3-rc2) and ran git submodule deinit mysubmodule. I then deleted the .gitmodules file and committed the change. I also deleted the…
Chris B.
  • 85,731
  • 25
  • 98
  • 139
71
votes
1 answer

git submodule update --remote vs git pull

What is the difference between running git submodule update --remote vs cd git pull Assuming that the submodule was previously set to track some branch: git submodule add -b master [URL to Git repo]
user2924714
  • 1,918
  • 1
  • 19
  • 26
70
votes
3 answers

Continue looping over submodules with the "git submodule foreach" command after a non-zero exit

I have a project that contains many submodules. I want to loop over each submodule with the following command: git submodule foreach npm install And I want the script to continue looping over each submodule even if one submodule returns an error…
Casey Flynn
  • 13,654
  • 23
  • 103
  • 194