What if two Git repositories share common code

I will not give advice on “How you should go about this”. But I’ll explain how to accomplish integrating a third repository with common code into the other repositories: This is a job for git submodules. git submodules allow you to reference a snapshot of a git repository at a specified path:

git submodule add git://example.com/repository.git path

Afterwards create a commit. Now a snapshot of the given repository is referenced at path.

Populating the submodule

  1. Execute git submodule init
  2. Execute git submodule update

Every configured submodule will be updated to match the state it is supposed to look like.

Updating a submodule to a later commit

  1. Change into the directory of the submodule
  2. Perform a git pull / git fetch + git checkout to update the submodule to the desired commit / tag
  3. Create a new commit to update the commit in the .gitmodules file

Take a look at the official manual for further information on submodules.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)