# git submodules.

2 messages from 2008-04-28 to 2008-04-28. Participants: Victor Bogado da Silva Lins, Miklos Vajna.
Thread: https://gitlist.dev/t/13312

## Victor Bogado da Silva Lins, 2008-04-28 19:50

Subject: git submodules.
Message-ID: <1209412220.29267.22.camel@omicron.ep.petrobras.com.br>
URL: https://gitlist.dev/e/1209412220.29267.22.camel%40omicron.ep.petrobras.com.br

```
Is there any documentation about how those work?

What I need is this, I have a already existing git repository, that have
a subdir that could be seen as submodule (by this I mean that he is
related, but could have a different commit tree). The git repository
already exists and has many commits that apply to either the submodule
or the main module (I would say that there is no commit that touch
both). So is it possible to separate them easily? Would it keep my older
commits? 

bellow is a shell script that samples my setup: 

=========================== cut here =================================
#!/bin/bash

gitdir=git_submodules_dir

if [[ -d $gitdir ]]; then 
	rm -rf $gitdir;
fi

mkdir $gitdir

cd $gitdir

git init

echo "testing 1 2 3" > file_a.txt
git add file_a.txt
git commit -m "initial setup"

mkdir submodule

echo "submodule file" > submodule/file_b.txt
git add submodule/file_b.txt
git commit -m "submodule file"

echo "updated main file" >> file_a.txt
git commit -a -m "updated file in main module"

echo "updated sumodule file" >> submodule/file_b.txt
git commit -a -m "updated file in the submodule"
=========================== cut here =================================

```

## Miklos Vajna, 2008-04-28 21:01

Subject: Re: git submodules.
Message-ID: <20080428210139.GH26880@genesis.frugalware.org>
URL: https://gitlist.dev/e/20080428210139.GH26880%40genesis.frugalware.org
In-Reply-To: <1209412220.29267.22.camel@omicron.ep.petrobras.com.br>

```
On Mon, Apr 28, 2008 at 04:50:20PM -0300, Victor Bogado da Silva Lins <victor@bogado.net> wrote:
> Is there any documentation about how those work?

Yes. There is a chapter in the user manual and there is the
git-submodule manpage.

> What I need is this, I have a already existing git repository, that have
> a subdir that could be seen as submodule (by this I mean that he is
> related, but could have a different commit tree). The git repository
> already exists and has many commits that apply to either the submodule
> or the main module (I would say that there is no commit that touch
> both). So is it possible to separate them easily?

Yes, see git-filter-branch.

> Would it keep my older commits? 

Not really, git-filter-branch will rewrite history, so the commit hashes
will change. Of course no code will be lost, but after such a migration,
people will not be able to easily just pull.

```
