git nested init
Turn an existing subdirectory into a nested repository.
git nested init [<options>] <subdir>
git nested init --from-submodule <subdir>
What it does
init writes <subdir>/.gitnested and commits it. The files in <subdir>
stay as they are.
Use it when:
you have code in your repository that should get its own upstream repository,
you have a copy of an upstream and know which upstream commit it is,
you want to replace a git submodule.
It needs a clean working tree. git must track files in <subdir>.
Arguments
Argument |
Meaning |
|---|---|
|
the folder to turn into a nested repository |
Options
Option |
Meaning |
|---|---|
|
the upstream URL or path. Without it, |
|
the upstream branch. Default: |
|
the upstream commit the current content is based on. Needs |
|
the join method. Default: |
|
turn the git submodule at |
|
GPG-sign the commit |
|
add a |
Examples
New code, new upstream
You have lib/ in your repository. Now it should live in its own
repository too:
git nested init lib -r https://github.com/user/lib
git nested push lib --commit
The upstream may be empty. The first push makes the branch there.
--commit records the pushed commit in .gitnested, so later pulls and
pushes start from it.
No upstream yet
git nested init lib
remote is none. Add it later:
git nested config lib remote https://github.com/user/lib
git commit -m "lib: set upstream"
A copy of upstream
ext/lib holds upstream commit abc123, maybe with your own changes on
top. Tell git-nested:
git nested init ext/lib -r https://github.com/user/lib --commit abc123
The next pull and push start from that commit. Your changes since then are
kept as local changes. If you do not know the commit, try
clone --adopt. It looks for a
matching commit.
From a submodule
git nested init --from-submodule ext/lib
This removes the submodule and clones the same URL at the same commit into
its place. A relative submodule URL is resolved against the origin remote
of your repository. See Upstream submodules.
Notes
--commitmust be a commit on the upstream branch.<subdir>must not have a.gitnestedyet.