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 .gitmodule file (for the url of the sub repo)
  • a special entry in its index, called gitlink for the SHA1 to which the submodule is checked out (a submodule is always initialized in a detached HEAD mode)

Common questions:

2611 questions
311
votes
14 answers

How do I revert my changes to a git submodule?

I have a git submodule (RestKit) which I have added to my repo. I accidentally changed some files in there and I'd like to go back to the source version. In order to do that, I tried to run Mac:app-ios user$ git submodule update RestKit But as you…
Eric
  • 4,607
  • 2
  • 22
  • 29
302
votes
4 answers

How do I work with a git repository within another repository?

I have a Git media repository where I'm keeping all of my JavaScript and CSS master files and scripts that I'll use on various projects. If I create a new project that's in its own Git repository, how do I use JavaScript files from my media…
Brent O'Connor
  • 5,042
  • 6
  • 20
  • 26
293
votes
5 answers

How do I "commit" changes in a git submodule?

I have, in my naivety, set up a git submodule and treated it like a Subversion external - i.e. it's now full of changes that I've just realized haven't been committed or pushed anywhere. Is there some easy way to commit/push the submodule changes…
Dylan Beattie
  • 50,029
  • 31
  • 120
  • 189
275
votes
19 answers

List submodules in a Git repository

I have a Git repository that has several submodules in it. How do I list the names of all the submodules after git submodule init has been run? The git submodule foreach command could echo the names of the submodule, but that only works once they…
tpg2114
  • 11,938
  • 6
  • 37
  • 54
260
votes
11 answers

Issue with adding common code as git submodule: "already exists in the index"

I'm new to git and would appreciate help with adding submodules. I've received two projects sharing some common code. The shared code was just copied into the two projects. I created a separate git repo for the common code and removed it from the…
Vanja
  • 3,835
  • 3
  • 23
  • 22
258
votes
10 answers

Git diff says subproject is dirty

I have just run a git diff, and I am getting the following output for all of my approx 10 submodules diff --git a/.vim/bundle/bufexplorer b/.vim/bundle/bufexplorer --- a/.vim/bundle/bufexplorer +++ b/.vim/bundle/bufexplorer @@ -1 +1 @@ -Subproject…
mrwooster
  • 22,109
  • 11
  • 34
  • 44
255
votes
4 answers

Git submodule update

I'm not clear on what the following means (from the Git submodule update documentation): ...will make the submodules HEAD be detached, unless --rebase or --merge is specified... How does --rebase/--merge change things? My main use case is to have…
deepblue
  • 7,836
  • 12
  • 45
  • 59
239
votes
8 answers

Is there a way to make git pull automatically update submodules?

Is there a way to automatically have git submodule update (or preferably git submodule update --init called whenever git pull is done? Looking for a git config setting, or a git alias to help with this.
philfreo
  • 36,787
  • 25
  • 119
  • 140
237
votes
6 answers

Git submodule add: "a git directory is found locally" issue

I'm actually trying to learn how to use git, including the git submodule subcommands. I already set up a server on which I can host, push and pull git repositories by using SSH. I created a main git repository "Travail" on this server in which I…
vmonteco
  • 10,994
  • 12
  • 43
  • 73
216
votes
4 answers

How to set up a git project to use an external repo submodule?

I'd like to create a repo which pulls in a remote repo. For example, let's say jQuery as a submodule: git://github.com/jquery/jquery.git What would be the process of creating a repo with jQuery as a submodule and adding my own external as a remote…
Tom
  • 30,868
  • 31
  • 81
  • 104
192
votes
8 answers

Why is my Git Submodule HEAD detached from master?

I am using Git submodules. After pulling changes from server, many times my submodule head gets detached from master branch. Why does it happen? I have to always do: git branch git checkout master How can I make sure that my submodule is always…
om471987
  • 4,741
  • 4
  • 27
  • 39
174
votes
7 answers

Rename a git submodule

Is there some easy way to rename a git submodule directory (other than going through the entire motion of deleting it and re-adding it with a new destination name). And while we are at it, why is it that I simply cannot do the following in the…
Lars Tackmann
  • 18,135
  • 13
  • 60
  • 80
163
votes
13 answers

How to track untracked content?

See below the solid line for my original question. I have a folder in my local directory that is untracked. When I run git status, I get: Changed but not updated: modified: vendor/plugins/open_flash_chart_2 (modified content, untracked…
sscirrus
  • 50,379
  • 41
  • 125
  • 211
163
votes
6 answers

Git: fatal: Pathspec is in submodule

I'm trying to get TravisCI to automatically deploy my Hakyll static site, according to this guide. Here's how my repo is set up. I have my source branch, which contains my hakyll and markdown files. It builds the html into the _site directory, which…
jmite
  • 7,320
  • 6
  • 32
  • 74
161
votes
1 answer

Where does Git store the SHA1 of the commit for a submodule?

I know that when you add a submodule to a git repository it tracks a particular commit of that submodule referenced by its sha1. I'm trying to find where this sha1 value is stored. The .gitmodules and .git/config files only show the paths for the…
Abizern
  • 129,329
  • 36
  • 198
  • 252