

If needed, create the parent directory of the new location of the submodule (`mkdir -p **new/path/to**`).

$ git mv **old/path/to/module** **new/path/to/module**Įdit `.gitmodules` and change the path of the submodule appropriately, and put it in the index with `git add.
#GIT ADD REMOTE SUBMODULE FREE#

Git remote add origin PUSH FILES TO REMOTE REPOSITORY git filter-branch -subdirectory-filter src/libs/Library1 -allĪs we are working on a clone of Project, origin is still pointing to the remote repository of Project. We want to remove that and make origin point to the new remote repository of Library1. Now it’s time to rewrite the repository to look as if Library1/ had been its project root, and discard all other history. The second step is cloning the Project repository to work on a new copy. Here /path/to/git/repos/ is the directory storing all the git repositories on your server. The following instructions assume that you are doing this on some server from the shell. The first thing to do is creating a new empty repository for Library1.
#GIT ADD REMOTE SUBMODULE HOW TO#
The following steps are based on the repository introduced in the previous section.They will explain how to turn a subdirectory of a project into an independent git repository and how to use this new repository as submodule, a foreign repository embedded within a dedicated subdirectory of the source tree of a project. From repository subdirectory to git submodule Maybe at some point you’ll want to make Library1 an independent git repository to share it with other projects preserving its previous history.Ī pretty easy way to achieve this is using git filter branch and git sumbmodule as explained in the next section. If you work with git repositories it’s probably only a matter of time until you’ll need/want to refactor them in order to share some parts or to create new repositories.įor example you have a repository with a layout similar to this one: Project/ This tutorial explains how to extract a subdirectory of a git repository and how to make it a submodule or an independent git repository in 8 easy steps.
