git nested branch
Create a branch holding the local nested commits.
git nested branch [<options>] [<subdir>]
git nested branch --all [<options>]
What it does
branch builds the nested branch nested/<subdir>. It holds the history of
<subdir> as if it were its own repository: the upstream commit, and your
local commits on top. .gitnested is left out.
The branch is checked out in a worktree. By default that is
.git/tmp/nested/<subdir>.
The branch tracks upstream through a git remote with the same name. So in
the worktree, plain git fetch, git pull and git push talk to upstream.
Use it to:
look at the nested history on its own,
fix up the history before a push,
finish a pull by hand. See Resolve conflicts.
Other changes in your working tree do not block it. If <subdir> has
uncommitted changes, branch warns and ignores them.
Arguments
Argument |
Meaning |
|---|---|
|
the nested repository. Can be left out inside it |
Options
Option |
Meaning |
|---|---|
|
build the branch for all nested repositories |
|
put the worktree here. Default: |
|
name the branch. Default: |
|
fetch upstream first |
|
build the branch again if it exists |
|
GPG-sign the rebuilt nested commits |
Examples
git nested branch ext/lib
git nested branch -d ../lib ext/lib
git nested branch --name lib-fixes ext/lib
git nested branch --all
Then work in the worktree:
git nested run ext/lib log --oneline
cd .git/tmp/nested/ext%2Flib
git commit --amend
cd -
git nested push ext/lib nested/ext%2Flib
Branch names
Case |
Branch name |
|---|---|
|
|
in a linked worktree |
|
with |
|
A name from --name is stored in .git/config, as
nested.<subdir>.branchname. So run, commit, push, pull and
status use that branch too, until git nested clean forgets it.
Notes
If the branch exists already,
branchstops. It shows what the branch holds, so you can decide: reuse it, use--forceto build it again, or remove it withclean.--dirpointing at the worktree of the same nested repository builds the branch again there. The worktree of anything else is never touched.A local branch called
nestedblocks thenested/...branches. Rename it, or use--name.--namecan not be the name of a branch git-nested does not own.--dirand--namecan not be used with--all.