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
141
votes
4 answers

Create a submodule repository from a folder and keep its git commit history

I have a web application that explores other web applications in a particular way. It contains some web demos in a demos folder and one of the demo should now have it's own repository. I would like to create a separate repository for this demo…
GabLeRoux
  • 16,715
  • 16
  • 63
  • 81
132
votes
3 answers

What is the point of 'git submodule init'?

Background To populate a repository's submodules, one typically invokes: git submodule init git submodule update In this usage, git submodule init seems to do only one thing: populate .git/config with information that is already in…
user82216
132
votes
4 answers

"You are on a branch yet to be born" when adding git submodule

I am attempting to add a few submodules to my .vim/bundles directory, and when I attempt to add this particular repo Git gives me a strange error I've never seen before: $ git submodule add -f git://github.com/derekwyatt/vim-scala.git…
matt b
  • 138,234
  • 66
  • 282
  • 345
126
votes
2 answers

Automatically access git submodules via ssh or https

Question: Is there a way to automatically checkout git submodules via the same method (ssh or https) as the main repository? Background: We have a non-public gitlab repository (main) that has a submodule (utils) which is also hosted as a non-public…
MikeMB
  • 20,029
  • 9
  • 57
  • 102
125
votes
5 answers

How to extract a git subdirectory and make a submodule out of it?

I started a project some months ago and stored everything within a main directory. In my main directory "Project" there are several subdirectories containing different things: Project/paper contains a document written in…
patch
116
votes
12 answers

Two git repositories in one directory?

Is it possible to have 2 git repositories in one directory? I'd think not, but thought I'd ask. Basically, I'd like to check in my home directory config files (e.g. .emacs) which should be common across all of the machines I work on, but have a…
Joe Casadonte
  • 15,888
  • 11
  • 45
  • 57
115
votes
6 answers

How to only update specific git submodules?

So, updating all my submodules is done by running git submodule foreach 'git pull origin master' How do I update a specific submodule, located in say bundle/syntastic, without updating any other submodules?
Calvin Cheng
  • 35,640
  • 39
  • 116
  • 167
111
votes
3 answers

How to clone only a folder from a git submodule?

I'm trying to get just a folder from an external github repo to use in my project. I want my project setup to be like this: -my_project -submodule -code.py -MY_README -.git And I have the remote repo named some-submodule with…
demula
  • 1,214
  • 2
  • 9
  • 12
110
votes
3 answers

How can I move a single directory from a git repository to a new repository whilst maintaining the history?

I have inherited a git repository containing multiple projects in separate directories. I'd like to split the repository into new individual repositories, one for each project and then have the master repository contain the projects as submodules.…
cidered
  • 3,241
  • 3
  • 25
  • 20
110
votes
6 answers

How do I replace a git submodule with another repo?

How do I replace a git submodule with a different git repo? Specifically, I have a submodule: located at ./ExternalFrameworks/TestFramework that points to a git repo git@github.com:userA/TestFramework.git I'd like it to now point to…
joseph.hainline
  • 24,829
  • 18
  • 53
  • 70
107
votes
5 answers

How to see which commit a git submodule points at

As far as I understand, if you add a submodule in git, then the main repo contains a pointer to a certain commit of the submodule. Is there any way to see to which commit the main repo points at for a specific submodule, without checking out the…
gitaarik
  • 42,736
  • 12
  • 98
  • 105
103
votes
3 answers

What is the way to remove a git submodule as of git version 1.9.3?

as of git version 1.9.3 (Apple Git-50) on mac how do i remove a git submodule? I am reading alot of outdated information with many developers telling me they wont work. What is the current way ? will git deinit pathToSubModule do the trick…
j2emanue
  • 60,549
  • 65
  • 286
  • 456
102
votes
7 answers

How to apply a git patch from one repository to another?

I have two repositories, one is the main repo for a library, and the other is a project using that library. If I make a fix to the in the subservient project, I'd like an easy way to apply that patch back upstream. The file's location is different…
James Wheare
  • 4,650
  • 2
  • 26
  • 22
102
votes
4 answers

Alternatives to Git Submodules?

I feel that using Git submodules is somehow troublesome for my development workflow. I've heard about Git subtree and Gitslave. Are there more tools out there for multiple repository projects and how do they compare ? Can these tools run on…
Chau Chee Yang
  • 18,422
  • 16
  • 68
  • 132
97
votes
8 answers

Restore git submodules from .gitmodules

I have a folder, which was a git repo. It contains some files and .gitmodules file. Now, when I do git init and then git submodule init, the latter command output is nothing. How can I help git to see submodules, defined in .gitmodules file without…
evgeniuz
  • 2,599
  • 5
  • 30
  • 36