Restore git submodules from .gitmodules

git submodule init only considers submodules that already are in the index (i.e. “staged”) for initialization. I would write a short script that parses .gitmodules, and for each url and path pair runs: git submodule add <url> <path> For example, you could use the following script: #!/bin/sh set -e git config -f .gitmodules –get-regexp ‘^submodule\..*\.path$’ … Read more

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

If manually editing the patch file is out of the question or infeasible, this can be done with standard options (available in git apply, git format-patch and GNU patch). -p<n> removes n leading directories from the paths in the patch. After processing -p, –directory=<root> prepends root to each of the paths in the patch before … Read more

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

You have the git submodule deinit git submodule deinit <asubmodule> git rm <asubmodule> # Note: asubmodule (no trailing slash) # or, if you want to leave it in your working tree git rm –cached <asubmodule> rm -rf .git/modules/<asubmodule> deinit Un-register the given submodules, i.e. remove the whole submodule.$name section from .git/config together with their work … Read more

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

You can use git filter-branch to rewrite the history of a project. From the documentation: To rewrite the repository to look as if foodir/ had been its project root, and discard all other history: git filter-branch –subdirectory-filter foodir — –all Make several copies of your repo, do that for each subdirectory you want to split … Read more

Two git repositories in one directory?

This article covers this relatively well: https://github.com/rrrene/gitscm-next/blob/master/app/views/blog/progit/2010-04-11-environment.markdown Basically if you’re working from the command-line this is simpler than you might guess. Suppose you want 2 git repos: .gitone .gittwo You could set them up like so: git init . mv .git .gitone git init . mv .git .gittwo You could add a file and commit … Read more