Git Branch
Conventions for the branches a repository carries — which one is a trunk, what a general
branch is called, the commit that opens a trunk and the commit that closes a sub-branch.
What belongs in a single commit, and how a subject is worded, are settled by the git commit
convention. The two commits described here are the exception it points at: their subjects are
specified in full below, because what they say is inseparable from what they are for.
No commit is made directly on `main`, `release/x.x.x`, `dev` or `env`
**A commit that carries a change of its own is never made while one of these four is checked
out, whatever the change is.** The only way a change reaches them is a branch merged back. The
two a trunk makes about itself carry none, and the bullet below names them. hotfix/xxxx is
not among the four; it is the one trunk worked on directly, as described under the trunk branch
below.
- Read the branch name before the first edit, and again before every commit. Run
git branch --show-current. Where the answer is one of the four, cut a branch for the change
before touching a file, and commit there. Uncommitted edits travel with git switch -c, so
noticing late costs nothing as long as nothing has been committed yet.
- Where no branch other than those four exists, a new one is created, without exception.
There is no branch to work on, so the work does not start until one exists. A repository
whose branches are all trunks, or a checkout sitting on one with nothing else cut yet, is not
a case for committing there. The work always goes onto a newly created branch, and its
commits are made on that branch, with no exception.
- Size, speed and tidiness are not exceptions. "One line", "a typo", "the tree is clean",
"I will move it to a branch afterwards" — none of them makes a direct commit permissible, and
a commit that is going to be moved is still a commit made on the trunk.
- Two commits are the only ones a trunk makes itself, and neither carries a change of its own:
the marker that opens it and the Merge … commit that brings a sub-branch in. Both are
described below.
- A commit already made on one of the four is recovered, and the recovery is not optional.
Noticing late does not end the work at a report. Say which branch and which commits, then put
the line back: the commits are given a branch of their own, and the trunk returns to where it
stood.
```bash
git branch <branch> # the commits are held by a ref of their own
git rebase --onto origin/<trunk> @ # the trunk goes back
git switch <branch>
```
- The branch is made before anything moves.
git branchnames the tip without switching,
so the commits are held before the trunk is touched. Stopped after that one command, the
recovery has lost nothing and can be picked up again.
git rebase --onto <target> @rather than a reset. The range@..HEADis empty, so
nothing is replayed and the branch simply arrives at <target>. Where a tracked file is
modified the rebase refuses and moves nothing, which is the whole of what separates it from
git reset --hard.
- Why the reset is refused rather than merely preferred against belongs next door.
/hoc-git-prohibit-destructive-commands is the convention that bars it, and the stash below
is that convention's mechanism, borrowed here. What this one settles is the shape of the
recovery: which ref holds the commits, where the trunk returns to, and which branch the pop
happens on.
- That refusal is what asks for
git stash. The open edits belong to the work rather than
to the trunk, so they are set aside before the rebase and taken back after the switch:
```bash
git branch <branch>
git stash -u
git rebase --onto origin/<trunk> @
git switch <branch>
git stash pop
```
-u, so that untracked files go with it. Only one the rebase would have to overwrite
stops it, but all of them are part of the open work, and leaving any behind splits it
across two places.
- The pop happens on
<branch>, not back where the stash was taken. The stray commits
changed the tree, the open edits may touch what they changed, and the rewound trunk no
longer carries any of it while <branch> still does. This is where the ordinary
stash-rebase-pop order does not reach: there the branch comes back to the work, and here
the trunk is moved away from it.
- Measured: with the open edit touching a file one of the stray commits had added, popping
on the rewound trunk came back DU and kept the stash entry, while popping on <branch>
applied clean.
- Where the trunk stood is
origin/<trunk>while the commits are unpublished. The trunk's
reflog answers the same question where the remote is not the reference.
- Where they are already pushed, the recovery is asked for rather than made. Putting the
trunk back then means rewriting published history, which is nobody's to do from here. Report
the branch and the commits, and ask for the trunk to be recovered before anything else is
taken up — /hoc-git-branch-remote settles what the trunk may do afterwards.
- Why the rule is this strict. A trunk's published history is never rewritten, so a commit
that lands on one cannot be taken back, and a change that skipped the branch skipped the one
step at which it could be read before it became part of the trunk.
Every rebase takes `-r`
**git rebase without -r (--rebase-merges) is forbidden. There is no ordinary case that
omits it.** Not preferred, not recommended where a branch has merges in it: the flag goes on
every invocation, and a command written without it is wrong whether or not this particular
branch happens to survive the omission.
git rebase -r <trunk> <branch>
git rebase -r --onto <trunk's new tip> <the commit this branch was cut from> <branch>
Without -r, git rebase drops every merge commit it replays. A branch that carried its own
sub-branches arrives flattened, and the --no-ff merges inside it are gone — the exact thing
--no-ff was used to keep. The loss is silent: the rebase reports success, the working tree
matches, and what is missing is structure no diff reports.
Whether the branch holds a merge commit right now is not the test. A branch with none loses
nothing today, but deciding case by case means re-examining the question at every rebase and
getting it wrong on the one branch that did carry a merge. The flag costs nothing when there is
nothing to preserve.
- The single thing that lifts it is a deliberate decision to flatten a branch's internal merges,
taken as such and said out loud. Nobody arrives there by default.
This rule stands ahead of everything below because the commands that need it appear throughout,
and because a rebase that drops a merge cannot be spotted afterwards from the result.
Editing a commit inside the branch takes `-i` as well
-r keeps the merges; -i is what opens the todo list. Given -r alone, a rebase runs the
sequencer but never presents a todo, so a sequence editor named in the environment is never
called — and the run reports every step successful while handing each commit back with the hash
it went in with.
git rebase -i -r --onto <base> <the commit the branch was cut from> <branch>
Measured on a branch carrying one merge: with -r alone the rebase printed eight steps and
Successfully rebased, and no hash changed. With -i -r the reword applied and the merge commit
survived, the graph keeping its shape.
- Being unable to answer a prompt is not a reason to avoid
-i. Point the sequence editor
and the message editor at scripts — one rewrites the todo, the other rewrites the message —
and nothing prompts. An interactive rebase can be driven rather than attended.
- Rebuilding the sub-branch by hand is the fallback for a conflict, not for a reword.
Cherry-picking its commits onto a fresh branch and amending the one that needed the new
subject reaches the same tree at the cost of the branch and every merge above it.
A rewritten trunk takes `--onto` as well
**git rebase -r <trunk> <branch> is right while the trunk only moves forward, and wrong once
the trunk has been rebuilt.** The two-argument form replays everything in <trunk>..<branch>,
and that range holds the branch's own commits only for as long as the commit the branch was cut
from is still on the trunk. Rebuild the trunk — rewind it and merge the sub-branches again — and
that commit is gone, so the range reaches back to whatever the two still share and sweeps up the
old trunk's merges on the way.
git rebase -r --onto <the trunk's new tip> <the commit this branch was cut from> <branch>
-r is what makes the damage silent. The flag exists to preserve merge commits, and it
preserves these too: the old trunk's Merge … commits are replayed inside the sub-branch, so the
graph comes out with two paths carrying the same subjects, and the branch appears to hold work
that was folded away. The rebase reports success and the tree is correct, which is why nothing
downstream catches it.
- The graph is where it shows.
git log --graphafter each rebase, and one merge subject
appearing twice is the whole of the symptom.
- Measured twice on one branch structure. Both times the trunk had been rewound and rebuilt,
both times the two-argument form recreated its merges inside the sub-branch, and both times
--onto naming the commit the branch was cut from replayed only what the branch held.
A commit the base already holds is dropped, not resolved
**A rebase onto a base that has moved past the branch replays commits whose change is already
there**, and the ones that conflict are the safe half. A conflict stops and asks; a commit that
applies cleanly does not, and where the base holds the same change at a different place in the
file, what lands is the change twice.
Measured twice, on two branches against one base: a conflict was resolved by taking the base's
side, a later commit in the same rebase then applied without conflict at its own anchor, and both
times the result was a configuration file carrying the same key on two lines. Both times the tree
was correct at every other point, the rebase reported success, and nothing downstream refused it.
- Establish which commits the base already holds before starting, and skip those rather than
resolving them. A patch already upstream has nothing to contribute, so the resolution never
needed judgment in the first place.
- The repair is to drop the commit, never to tidy the result. Editing the duplicate away
leaves a commit in the branch claiming a change the base had already made, and the next rebase
of that branch makes the same duplicate again. Drop it with -i -r, which keeps the merges the
-i would otherwise cost.
- Read the result against the base before merging. Where a branch was expected to add
something and the diff shows a line the base already had, the duplicate is what it is showing.
The trunk branch
A trunk branch is one that other branches are cut from and merged back into.
**Five are trunks by name, in every repository: main, and the four branches that may merge
into it.**
| branch | what it carries |
| :-- | :-- |
| main | the mainline every other branch descends from |
| release/x.x.x | one version's work, until it merges into main |
| hotfix/xxxx | one fix that cannot wait for a release |
| dev | long-lived integration. Legacy |
| env | the initial environment setup, and changes that leave the released artefact untouched |
Every other branch is a general branch, and takes the role rather than holding it. A
general branch behaves as a trunk for as long as work is split off it. The five above behave as
trunks whether anything is outstanding against them or not.
devis legacy. It stays in the set for backward compatibility, and nothing new is opened
on it. A repository still carrying one holds it to every rule here.
- Which of the four a given repository may merge into
mainis narrower than the set, and
it is decided by the kind of repository — see /hoc-git-branch-remote. **The set here is the
ceiling, not the instruction.**
The shape of the name settles nothing. release/x.x.x is a trunk and
retake/save-of-UserRepository is not, and the two are the same shape.
- Trunks nest. A general branch cut from a trunk that then has work split off it is both: a
sub-branch of that trunk, and the trunk of what it carries. The role is held against a particular
branch, never held outright.
- Each half brings its own obligations, and neither cancels the other. Being a trunk, the
branch opens with the Start … marker described below; being a sub-branch, it merges back
into the trunk it was cut from once it is done. That the merge is made locally, with no pull
request to open early, takes nothing away from the marker.
- A sub-branch merges back into its trunk, and a trunk never merges into what it carries.
The direction is the same at every level of the nesting.
- A trunk is where work arrives, not where work is done. Nothing is committed to a trunk
directly: cut a branch for the change, commit it there, and merge it back. This holds for a
general branch from the moment it takes the role, and it holds on a trunk whose only commit so
far is its own opening marker — a trunk with nothing on it yet is still not a place to work.
- The exceptions are the two commits a trunk makes about itself rather than about the work:
the marker that opens it, and the Merge … commit that brings a sub-branch in. Both are
described below, and neither carries a change of its own.
hotfix/xxxxis the one trunk worked on directly. The fix is committed onto it, with no
sub-branch and no marker, and the branch merges into main as it stands.
- The reason is what the branch is for. It exists to carry one fix past the release that
would otherwise have carried it, and every step between the fix and main is time the
failure it fixes is still running. A sub-branch and its merge buy structure that nothing is
going to read on a branch holding one fix.
- It is a trunk in every other respect. Its history is not rewritten once pushed, it
reaches main through a pull request like the rest, and it is deleted on merge.
- A trunk's published history is never rewritten — what that forbids, why, and the one case a
trunk may be re-cut belong to /hoc-git-branch-remote.
- A sub-branch is the opposite, until it is pushed and opened for review: rewriting it is
how the structure described below gets cut at all. Nobody else is holding it, so nothing
disagrees.
What may be cut from `main`
Under Git flow, only a branch whose name is one of these is cut from main or origin/main:
| Kind of repository | Cut from main |
| :-- | :-- |
| boilerplate | release/x.x.x |
| npm package | release/x.x.x, env |
| application | release/x.x.x, env, hotfix/xxxx — and dev, in an older application only |
Every other branch is cut from one of these. **Where the one it needs does not exist yet, it is
opened first**, and its version is asked rather than assumed; no branch is cut from main in its
place.
The list repeats the table of /hoc-git-branch-remote, which stays its source, so that it stands
where a branch is cut and not a skill away.
A general branch taken straight off main has nowhere to land: the four are what main accepts, a
guard on main refuses the rest, and the branch arrives at a base it is not allowed to merge into.
Under GitHub Flow every branch is cut from main and returns to it, because there is no
other trunk to cut from. So one and the same branch is correct in one repository and stranded in
the other, and which it is cannot be read off the branch itself.
Ask which flow the repository is on before cutting a branch from main. Nothing announces
it: a repository that has not yet opened dev, env or a release looks exactly like one that
never will, and a wrong guess is not found until the pull request is refused. The tells are the
four names and a guard on main — where none of them is there, the repository is on GitHub
Flow, and cutting from main is what it wants.
- This is the only branching question that is asked rather than decided. Everywhere else
this convention settles the answer itself, because the answer does not change between
repositories. Here it does, and the cost of assuming is a branch that has to be rebuilt.
When the structure is decided
Commit the work in one line first, and shape the branches once it is finished. The line is a
branch cut from the trunk for the purpose, never the trunk itself — a line committed onto
main, release/x.x.x, dev or env is the direct commit the first section forbids, and
cutting the markers afterwards cannot undo it. How many
sub-branches the work wants, and whether it wants a trunk at all, are answers the work itself
gives — and it cannot give them before it exists. A structure chosen in advance is a guess, and
a guess that turns out wrong costs a rebuild of everything already committed under it.
This is the opposite timing from granularity, which the git commit convention has decided
while working: by the time the tree holds six unrelated edits, the cheap moment for that one
has passed. Both rules say the same thing — decide at the point where the answer is knowable —
and the answers become knowable at different points.
So the order is: commit in a meaningful sequence until the work is ready for review, fold
together whatever turns out to be one decision after all, and only then cut the markers and
split the line into sub-branches.
- Every sub-branch is cut from the trunk, never from the sub-branch before it. Splitting a
finished line means returning to the trunk for each cut, not walking forward along the line as
the branches come off it. A branch cut while standing on the previous sub-branch carries that
branch's commits as well as its own, and the two arrive at the trunk stacked instead of side by
side — the second merge then reopens a line the first one closed.
- What
git branchshows afterwards looks the same either way. Only the commit each branch
was created from tells the two apart, and by the time the merges expose it the structure is
already built.
- The exception is a branch that cannot stand up without another one's work, where that
other reaches the trunk by its own pull request rather than by the local merge described
below. Sitting on it is how the prerequisite is had, and the reason the rule gives — a second
merge reopening a line the first one closed — does not reach the case, because the two never
merge into the trunk together. When the prerequisite lands, rebase the stack onto the trunk's
new tip and carry on.
- This holds only while the commits are unshared. Folding and splitting both rewrite
history. Once the work has been pushed, the line stands as it is, and a structure it did not
get is a structure it does not get.
- A finished line is turned into the structure by going back to a diff. The line is kept
under a tag before anything moves, so that the original is one git switch away. The branch
is then reset to its base without touching the working tree, which turns the commits back into
a diff, and the pieces are committed afresh, each sub-branch cut from the trunk.
- A change found after the structure is built is folded by kind, never by cause. A
documentation fix that surfaces once the code and documentation sub-branches exist goes onto the
documentation sub-branch, as one more commit beneath its single merge. It does not go into the
code commit whose change left the document stale, and it does not open a second documentation
sub-branch beside the first.
- Folding into the causing commit is the move that reads as tidy, the change and its
consequence side by side, and it is the one ruled out: it carries a documentation edit into a
code sub-branch, which the ordering below keeps apart.
- The marker is cut as part of that shaping, which is why there is no separate rule for
rewinding a trunk to insert one that was forgotten. A marker cannot be forgotten by a process
that ends with cutting it.
What the finished line is looked at for:
- One sub-branch's worth of work needs no trunk. A single branch carrying the commits
reaches the same pull request. A trunk earns its two extra commits — the marker and the merge
— by grouping several pieces of work, and there is nothing to group.
- Sub-branches that each carry one commit need no trunk either. The merge commit's subject
then restates the single commit beneath it, and the structure costs more commits than the work
contains. A trunk is worth its cost when a merge commit names something its commits do not say
individually.
- One sub-branch with something to group is enough to decide for a trunk. What makes the
trunk worth having is that at least one merge names a piece of work assembled from parts.
- The commonest piece assembled from parts is a pair whose halves mean nothing apart — a
test and the implementation it checks, an export barrel and the test naming what it exports,
a registration removed and the file it pointed at rewritten. Neither commit says on its own
that the two are one piece, and neither says where the piece ends.
- What the merge names is that boundary, never a summary of the commits beneath it. Read as
a summary it looks redundant over two commits whose subjects are already plain, and the
sub-branch is then given up for a cost it was not paying: the bullet above turns away a merge
that restates one commit, which a pair's merge does not do.
- **Once the line is to be a trunk, a sub-branch carrying a single commit is avoided as far as
the work allows.** Its merge restates the one commit beneath it, which is the cost the bullet
above weighs against having a trunk at all; deciding for the trunk does not make that cost go
away for the sub-branch.
- A translation pair that would be the sub-branch's only commit splits by language —
when, and when it folds back, belong to granularity.md of /hoc-git-commit.
- This is decided after the trunk, never before it. Splitting a commit to give a
sub-branch two is not a reason to cut a trunk; the bullets above settle whether there is one.
- **A sub-branch of its own is decided twice over: by what the piece carries, and by whether it
stands beside the others as work in its own right.** The bullets above settle the first. The
second asks whether the pieces are siblings — each a thing that was done, reviewable on its own
merit — or steps toward one thing they share. **Steps of one piece go in one sub-branch,
however much each carries.**
- Two classes reshaped, each for reasons of its own, are siblings: either could be taken and
the other left. A fix to the code and the removal of the relaxation that fix made unnecessary
are not — the second exists only because the first happened.
- Looking like siblings is not being siblings. Two methods rewritten, in two files, in two
classes, read as a pair of independent jobs. If neither of them alone clears the thing the
work set out to clear, they are halves of one job and belong on one branch.
- Deciding on size alone splits a pair that should have been one branch, because size is the
test that a pair of one-commit steps passes and a pair of large steps fails.
- New definitions and the adoption of them are the asymmetric pair, and they split. Where
a change introduces classes or members that did not exist and then adapts the existing code
to use them, the seam between the two is where the sub-branches part: one defines, one
adapts. The pair looks like steps of one piece — nothing uses the definitions until the
adoption lands — but only one half of the test holds. The definitions stand on their own:
they compile, they carry their own tests, and they could be taken while the adoption is left.
The adoption could not. That asymmetry is what the earlier examples lack, where neither half
means anything without the other.
- The adapting half is not split further by class or by file. Three classes changed so
that one new family can be used are three parts of one adoption, and they belong on one
sub-branch; splitting them by class produces siblings that are not siblings, which is the
failure the bullet above describes.
- Which half merges first follows the ordering rules below — the adoption cannot land before
what it adopts.
- Pieces that are one commit each and share a reason stand in one sub-branch, in a line.
Where every one of the commits was made for the sake of the sub-branches that follow, the pieces
are not siblings to be merged one by one or bundled in an octopus: they stack in one sub-branch
and merge once, and the merge says the shared reason in one sentence, as ## The merge commit
requires. A piece that takes more than one commit does not stack. Where even one of the
pieces is several commits, none of them is stacked, and each keeps a sub-branch of its own.
- A helper written for one class travels with that class. A class that exists only to serve
another — a workaround the class calls, a collaborator no other class uses — is not a sibling of
the classes around it. The two are gathered under a nested trunk named for the class they
serve, with the helper's sub-branch first and the served class's after it. Each keeps its own
sub-branch, so the trunk groups two pieces of work rather than folding them into one.
- A difference of kind puts a level between siblings. Where the pieces are siblings by the
test above, and one of them is an artefact written for the first time while the rest change
what already stands, they do not sit side by side. The like ones gather under a nested trunk
of their own, and the levels then hold the two kinds apart.
- It is not the sibling test failing. Each piece still stands as work in its own right,
and each still takes a sub-branch. What the difference of kind settles is the level one sits
at, which the sibling test does not reach.
- The boundary is the commit convention's vocabulary.
Declare,Define,Authorand
Build name what did not exist before; Update, Retake and Fix name what did. A trunk
whose sub-branches take verbs from both sides is what this bullet turns away.
- What the levels buy is a merge list that sorts itself. A trunk's merges are read as the
list of what the work did, and one mixing a thing that was made with three adjustments to
things that already stood gives the reader nothing to sort by. Gathered, the adjustments
arrive as one entry and the new thing stands beside it.
The order the sub-branches merge in
Merge the cheap ones first and the substantial ones last. Where one sub-branch changes a line
of configuration and another changes the code behind it, the line of configuration goes in first
and the code last. That is the order for a trunk that only groups pieces of work standing apart
from each other. A trunk named for one logical piece of work is ordered by what the work needs,
and the first bullet below sets that out.
The reason is what a diff from the newest commit holds. Commits run from the earliest at the
bottom to the latest on top. The sub-branch merged last is the largest, so a diff taken from the
newest commit is that branch's alone, with none of the small sub-branches' noise mixed in, and
checking it costs less. Merged earlier, the small ones sit beneath and stay out of that diff,
which costs little: the diff of a small commit is often what its message already says.
- **A trunk named for one logical piece of work merges its sub-branches in the order the work
needs, and size does not enter.** Where the sub-branches are the steps of one resolution — the
declared dependencies raised, then the locked versions moved within their ranges, then what an
audit still reports overridden, then the install-script settings decided against the tree that
results — each step presupposes what the one before settled. The order of necessity is the order
the work is read in, and ranking by diff cuts it.
- The test is what the trunk is named for. A trunk named for a purpose, such as resolving an
audit, is logical work and takes this order. A trunk that gathers pieces any of which could
be taken and the rest left follows the size order above.
- The order is read off the issue's
# Checklist. Its##headings already stand in the
order of necessity, so the merge list reproduces them, and a merge list that disagrees with
them is the one to suspect.
- Measured. A trunk resolving an audit was ordered by diff, and the sub-branch settling the
install-script entries merged first, ahead of the dependencies those entries are decided
against. Ordered by necessity, the same sub-branches read as the work does.
- The rule below still holds inside it. A change that only becomes possible once the others
land goes last, and the entries decided against the settled tree are the plain case.
- Size is read off the diff, never off the commit count. A diff from the newest commit is
what gets checked, so the diff is what ranks the branches. A branch of four commits that raise
versions and regenerate a lock file is cheaper to read than one of two commits that change a
procedure.
- An octopus merge is ordered by commit count, not by diff. Its branches arrive in one merge
commit, and git log --graph stacks their commits in the order the arguments are given — the
first argument at the bottom, the last on top, whatever the dates of the commits. The branch
with the fewest commits is the first argument and the one with the most is the last; branches
with the same count are ordered by diff, the smaller first. How the octopus merge is made is
under ## Merging back into a trunk.
- The rule above is the sequence's alone. A sequence of local merges ranks by diff, and an
octopus does not follow it there.
- This is not an argument about risk. Ordering by cost so that the cheap gains survive if the
expensive work is rejected reaches the same order by another route, and it is not the reason.
- A change that only becomes possible once the others land goes last, whatever it costs. Where
several sub-branches each clear the way for one change to a file they share, that change is not
spread across them: it gathers into a sub-branch of its own, placed after them. A relaxation
removed only once every file it named has been fixed is the ordinary shape of this.
- Documentation that follows the code takes this shape. Where the work moves
something a document states — a default, a return value, what is thrown — the document's
update exists only because the code moved. It is not placed in the sub-branch that moved it,
nor in that sub-branch's commit: it gathers into a documentation sub-branch of its own, merged
after the code sub-branches, however many of them moved what it states.
- **The settings a change needs in order to be accepted go in before the change, each as a
sub-branch of its own under a trunk for the environment.** A lint rule turned off for a file,
an entry in the spelling dictionary, an editor setting: whatever the tooling has to allow for
the new code to pass. Settings of different kinds are different pieces of work, not steps of one
— a linter's and a dictionary's are siblings — so each takes a sub-branch of its own, and the
group is gathered under a nested trunk named for the environment, merged ahead of the code it
serves. Where they are one commit each and were all made for the sake of what follows, the
stacking rule under ## When the structure is decided puts them in one sub-branch instead.
- Where that rule does not apply, single-commit sub-branches are kept. They are siblings
that differ in kind from the code and from each other, and bundled into one octopus merge
under the environment trunk they cost the reader a single line.
- A dependency install never shares a sub-branch with an environment setting. An install
changes what the project depends on and regenerates the lock file; a setting changes how the
tooling reads the code. They are different pieces of work, and each answers to a different
rollback. The install is a sub-branch of its own, never one of the settings under the
environment trunk.
- **A piece that directly serves the implementation stands immediately before it, whatever its
size.** The order by cost ranks pieces that have no bearing on one another. Where one piece
exists for the implementation — the packages its classes import — it is placed next to the
implementation, and nothing unrelated is put between them: a test double that only the suite
uses stands further back than the packages the classes depend on. A reader walking the merges
then meets the implementation straight after what it needs, rather than reading past a merge
that has nothing to do with either.
- Where the sub-branches gather a class family, the
Base~class goes first, and goes alone.
A feature trunk bundling the implementation of a family merges the branch carrying the Base~
class on its own, before any branch carrying a class derived from it.
- In a sequence of local merges the reason is the suite. Merge a derived class first and
the suite fails at that merge commit, because the class it extends is not on the trunk yet.
- An octopus merge never carries it. An octopus bundles branches of equal standing that
stand in parallel, and a Base~ class does not stand equal to the classes derived from it:
they are built on it. It is merged first, by itself, and the derived classes that remain,
independent of one another, may then go as an octopus on the tip that merge made.
- It stands ahead of the orderings above. A
Base~branch larger than the rest still goes
first.
- A family's barrel belongs inside the family's trunk, as the last sub-branch. The barrel
registers the classes of the family, so it depends on every one of them and has no meaning
without them. Merged as a sibling of the family at the top level, it stands apart from what it
registers; inside the family's trunk it comes after the last class and closes the trunk.
- **An octopus merge bundles branches of equal standing, and a module that only declares types
does not stand equal to what it declares.** Where one trunk gathers both the implementation of
a class family and such a module, the implementation branches are what the bundle holds, and
the declaring branch is not among them.
- In a sequence of local merges it goes last, after every implementation branch.
- In an octopus merge it is not a leg. Bundle the implementation branches, then merge the
declaring branch on its own, onto the tip the octopus has just made.
- The suite settles nothing here. A module read only by the annotations around it is
depended on by nothing at run time, so it stands wherever it is put and no merge commit
fails. Where the rule above takes its answer from the suite, this one has only the reading.
- The commit verbs settle nothing either. The declaring branch and the branches it declares
for can both open with verbs for what did not exist before, so the difference of kind that
puts a level between siblings does not reach this. What parts them is that one is implemented
and the other describes it.
- Type declarations are not written into the implementation sub-branches at all. A change
to the declarations — a global type, the type-level exports of the classes — is not folded
into the sub-branch of the class it describes. All of the work's type changes gather into one
independent sub-branch, merged last: after the implementation, and after the run-time export
of the same classes, which the type-level export mirrors.
- The order reverses where the sub-branches reach the trunk through pull requests. Then the
substantial one goes first and the cheap ones follow it. The reason above does not reach that
case: a pull request is read on its own rather than as a diff from the newest commit, so there
is nothing for an earlier merge to be hidden beneath. What the order decides instead is which
piece of work the reviewer meets first, and that is the one the rest depends on.
- The two rules are told apart by the route, never by the work. The same pair of branches
takes one order merged locally and the other order opened as pull requests, so the question
to ask is how they reach the trunk — not how large they are, which is what both rules
measure once the route is known.
- Do not reorder the merges to dodge a rename. A rebase carries a commit onto a file its base
renamed underneath it. Measured on a branch whose base had renamed a file the branch edits: the
edit landed on the new name, every merge the branch held survived, and the tree came out
differing only by what the new base added. A conflict predicted there is not a reason to put a
branch anywhere but where its size says.
The same work across sibling repositories takes the same order
Where one piece of work lands in two repositories at once, the sub-branches under each trunk
are cut in the same sequence, so the two histories read alike. Put whatever is peculiar to one
repository first and whatever both share last: the shared part then sits at the same depth in
both, and a reader comparing them has the differences gathered at one end rather than
interleaved.
Where a repository has nothing to put in the position its sibling fills, it skips that position
rather than filling it with something else. A gap in one of two matching sequences still reads
as a match; a substitution does not.
Naming a general branch
A general branch is named <verb | category>/xxxx. Before the slash goes a verb for what the
branch does, or a category for what kind of work it is; after it, the name is free — an
identifier may appear verbatim.
declare/AlphaClass
define/sendMessage-of-AlphaClass
rename/FormElementClerk
fix/type-errors-reported-by-the-client-package
install/date-fns-4.1.0
tidyup/environment-files
The name is written for whoever scans git branch while the work is still in flight, so it
is deliberately descriptive. It outlasts the branch, too: the merge commit a host writes records
it, as Merge pull request #<number> from <owner>/<branch>, and that line is read in git log
long after the branch is deleted.
- The verb is the word the branch's own commits would use, lowercased.
Declarenames a
class and Define names a member, a function or a constant, which is why
declare/AlphaClass and define/sendMessage-of-AlphaClass say what they carry without any
further explanation. The verbs are listed in the git commit convention.
- A verb of two words joins into one, as
/hoc-git-commitsays —Tidy upgives
tidyup/xxxx.
- A member is written
<member>-of-<class>. The slash is already spent on the verb, so what
is left spells the relation out instead of punctuating it.
- Work that recurs carries the value that tells one occurrence from the next. Raising a
package's own version is done once per release, so a label naming only the thing touched
returns, unchanged, for every release, and the merge commits it leaves in the history read
alike. The version, or the package and its version, goes into the label, as install/date-fns-4.1.0
already does.
```
Bad update/package-version
Good update/package-version-0.2.0
```
- The test is whether the same label could be cut again for other work. Where it could, the
label is missing the value that would stop it.
- A value that tells occurrences apart is not a connector. It names which occurrence this
is, where a connector joins two things the branch carries, which the rule on altitude below
turns away.
- **Work of a scale that will make the branch a trunk takes a category at a higher level of
abstraction** — implement/xxx, setup/xxx, feature/xxx, retake/xxx, update/xxx. A
branch that is about to have six branches cut from it cannot be named for one narrow verb
without lying about five of them.
- A branch whose work has outgrown its name is renamed before the structure is shaped. A
branch opened for one tidy-up that has grown into the implementation of a whole mechanism still
says tidyup/xxxx, and the name is now a claim about the work that is false. git branch -m
brings it to the altitude of the work, the one its opening marker is written at, and the label
and the marker then say the same thing.
- A sub-branch cut from a general branch acting as a trunk is named the same way, and the
nesting adds no constraint of its own: <verb | category>/xxxx, free. The narrow verbs
belong here, where each branch really does carry one thing.
- Leave out the article.
kickout/the-copied-rulesandkickout/copied-rulespoint at the
same work, and the shorter one is what a reader scanning git branch gets through faster.
What comes after the slash is a label, not a sentence.
- The label names the whole at one altitude, and never lists what the branch carries. A
branch holding two changes is still one branch, and a connector in the label hands the reader
the division before the thing. Where several changes land on one thing, the label is that thing
and the changes are what the commits are for. That a text never enumerates, whatever the
connector, belongs to /hoc-notation; this is the one place the rule bites for the reader
scanning git branch.
```
Bad add/retry-and-timeout-options-to-AlphaClient
Good update/AlphaClient
```
The altitude to find is the one the changes sit beneath, and it is usually already named —
the class, the module, the document they all touch. A label that reaches for a connector is one
written before that name was looked for.
The branch-opening marker commit
A branch that will act as a trunk opens with an empty commit whose subject begins with
Start — or with Release, on a release/x.x.x trunk. This is a deliberate convention, not a
checkpoint or a placeholder.
# opening a long-lived dev branch
git switch -c dev
git commit --allow-empty -m 'Start dev'
# opening a general branch that will carry sub-branches
git switch -c feature/equip-tools-for-each-application
git commit --allow-empty -m 'Start adding the skills installer'
# opening a nested trunk: cut from the branch above, and carrying sub-branches of its own
git switch -c update/domains-a-repository-selects
git commit --allow-empty -m 'Start updating the domains a repository selects'
- It must be empty (
--allow-empty). It exists to put a commit on a branch that has no
work on it yet, so there is nothing for it to carry. A Start … subject on a commit that
actually contains changes is not this convention — it is a mislabelled change.
- It is the first commit on the branch, made immediately after branching.
- One per trunk, and none on a sub-branch. The test is the branch's role: will other
branches be cut from this one and merged back into it? Where the answer is yes, the branch is
a trunk — that is what this document defines the word to mean, and that definition is the
whole of the condition.
hotfix/xxxxis the exception, and it is the same test that exempts it. Nothing is cut
from it, so there is nothing for a marker to open. A branch whose first commit is the fix
needs no commit placed ahead of the work, because the work is already there.
- A nested trunk takes a marker of its own. A general branch cut from a trunk that then has
work split off it is a sub-branch and a trunk at once, and it is the trunk half the marker
answers to. Such a branch merges back locally, with no pull request anywhere in it, and it
still opens with Start ….
- Whether a pull request is ever opened decides nothing. Where the merge does go through a
host, the marker buys a branch that can be reviewed before any code exists — but that is
something the commit makes possible, never the test for making one.
Startis not a verb for resuming work mid-branch. A branch already carrying commits has
nothing left to open.
- The subject is written at the altitude the branch name is written at. Both name one piece
of work, so a marker listing what the branch will carry fails the same way a label does, and
the two then disagree besides.
- The marker tests what the branch holds. Where the subject cannot name everything the branch
carries without stretching, the branch is what is wrong — not the subject. A marker reading
Start implementing the validator family over a branch that also rewrites the engine using it
is not a marker that needs rewording; it is a branch carrying two pieces of work, and the
second belongs beside it rather than under it. Writing the marker is therefore the moment the
contents get checked, which is one more reason it is cut while the structure is being shaped
rather than at the start.
- Hold the marker's verb against the verbs each sub-branch's commits open with. Those verbs
were settled one commit at a time, by what each commit did, so they are the record of what the
branch holds; the marker's verb is chosen once, for the whole, and nothing else reads the two
side by side. Where a sub-branch opens with a verb the marker's verb cannot speak for, that
sub-branch is the second piece of work the bullet above describes.
- The verbs do not have to match. A trunk-scale verb gathers several commit verbs beneath
it: an update of things that already exist takes Add, Kick out and Fulfill as parts of
itself. The question is whether the marker's verb still names what each of them did.
- A marker verb taken from the commit table keeps its commit meaning, and speaks only for
what that meaning reaches: Start updating the skills cannot speak for an Author commit,
because an update carries forward what was already there. **Enhance and Implement are
kept out of that table for this reason** — each names a whole piece of work rather than what
one commit did, so a thing written for the first time is part of one. The git commit
convention says why they are kept out.
- Measured. A trunk opened with
Start updating the skills by feedbacktook in a sub-branch
whose commits opened with Author: a skill written for the first time, which no update of
the existing skills covers. The issue written at the trunk's altitude inherited the marker and
took the new skill in under it, so the mismatch outlived the branch. The marker's verb was
updating, and that is where it failed: Start enhancing the skills would have held the
same sub-branch.
- The subject names what is being started, which depends on the kind of trunk.
- A
devtrunk is named directly:Start dev. Heredevis the branch, not a
placeholder word.
- A general branch acting as a trunk states the work it will carry, and the shape is
Start <verb>ing xxxx — the verb in its -ing form, then what it acts on.
```
Start adding the skills installer
Start renaming kit/skills/_core/ to core/
Start updating the domains a repository selects
```
A later reader scanning the log gets the branch's purpose for free.
- An
envtrunk takes that same shape rather than its own name — `Start provisioning
environment, Start setting up the environment. It is a trunk by name like dev`, and
unlike dev the name says nothing about which environment work is being opened.
- What follows the verb is the thing being provisioned, never the branch.
Start env
names the branch and stops there, and Start provisioning env puts the branch back into
the slot the work belongs in. Either way a reader scanning the log learns only which
branch they are on, which the ref beside the subject has already told them.
- A
release/x.x.xtrunk is opened by its version alone:Release 0.2.0. The word
Start does not appear, because the version is the whole of what is being started.
- Where the work carries content in from elsewhere, the marker names the origin — `Start
migrating the mail templates from sample-app`. Stated once here, it covers every
commit on the branch, and the merge commit keeps it in the history after the branch is gone.
- The marker takes no type prefix, in either message format — see
format-conventional.md
of /hoc-git-commit.
The merge commit
A branch merges back into its trunk with --no-ff, and the merge commit that results carries a
subject of its own.
Merge the classes of the skills installer
Merge the core/ rename in the repository documents
- It names the work, never the branch.
Merge rename/FormElementClerksays only what
git log --graph already shows, and the branch is deleted moments later. What it carried is
the part that has to survive it.
- It is one short sentence saying what the sub-branch did, and it enumerates nothing. A
sub-branch under a trunk is the thing that sentence says, so a subject needing and, or any
connector that lists what the branch carried, describes two sub-branches written as one, and
the branch is split until each has a sentence of its own. The commits that one sentence covers
stand in one sub-branch and merge once. That a text never enumerates, whatever the connector,
belongs to /hoc-notation; this is where the rule bites for a merge subject.
- It stands in for the message a host would have written. A merge that goes through a pull
request is described for free — Merge pull request #53 from …. A merge made locally has no
such author, and this subject fills the gap.
- It takes no type prefix, in either message format — see
format-conventional.mdof
/hoc-git-commit.
- A merge made through a pull request is left alone. The host writes it, and no one here
chooses its wording.
Merging back into a trunk
- Into a named trunk, the merge is made on the host, through a pull request — see
/hoc-git-branch-remote. What follows is how a branch merges back locally, into any other
branch acting as a trunk.
- Always
--no-ff, never fast-forward. A fast-forward leaves no commit a human can point
at: the branch's commits are strung onto the trunk's line, and the fact that they arrived
together, as one piece of work, stops being visible at all.
- Before each merge, confirm the branch is fast-forwardable.
--no-ffis only doing its
work when a fast-forward is what would otherwise have happened. On a branch that has fallen
behind the tip, git makes a three-way merge regardless, and the flag changes nothing.
```bash
git merge-base --is-ancestor <trunk> <branch> # must succeed
```
Failure means the branch has not been rebased onto the current tip. Rebase it, then merge.
- A merge commit's two parents are not evidence that
--no-ffdid anything. A three-way
merge has two parents as well, and nothing in the finished history separates the two. That
is why this is checked before the merge, and cannot be checked after it.
- The tip it is checked against has to be the trunk's current one. Where the trunk also
takes pull requests on the host, the local ref is only as new as the last time it was moved,
and a merge landed there on the host is not in it. The check then passes against a tip the
remote has left behind, the merge lands on that stale tip, and the trunk no longer
fast-forwards to what the remote holds. So fetch first, and advance a trunk that is behind
before checking anything — standing on the branch, since the refspec will not move the ref
that is checked out:
```bash
git fetch origin <trunk>:<trunk>
git rebase -r <trunk> <branch>
git merge-base --is-ancestor <trunk> <branch>
```
Measured: a local release trunk stood one pull request behind its remote, and a branch cut
from it passed the ancestry check against the local ref. Only a comparison with the
remote-tracking ref showed that a pull request had already merged there.
- **Before each merge, and before a pull request is opened, the suite is green at the branch's
tip.** The commits inside a branch may stand red on purpose, as /hoc-git-commit-order lays
out; the branch as a whole may not, at the point it goes back. Run the suite after the rebase
above, on the tip that will merge — see /hoc-workflows.
- Delete the branch once it is merged. Its name was written for whoever watched the work in
flight, and that reader is gone. This includes a trunk that merges into another trunk —
release/x.x.x, hotfix/xxxx, dev and env are all deleted once they land on main.
git branch -djudges against the branch's upstream, not against where you are standing.
A sub-branch that was given one is refused although the trunk in front of you holds every
commit it carries:
```
warning: not deleting branch 'add/xxxx' that is not yet merged to
'refs/remotes/origin/release/x.x.x', even though it is merged to HEAD
error: the branch 'add/xxxx' is not fully merged
```
Unset the upstream and delete again:
```bash
git branch --unset-upstream <branch>
git branch -d <branch>
```
-D is not the answer to this. It deletes whatever it is given, so it removes the check
rather than the cause — and on the one branch where the check was right, nothing is left to
say so.
- The upstream arrives from the start point.
git switch -c <name> origin/<trunk>sets
one and git switch -c <name> <trunk> does not, so a branch cut from a remote-tracking ref
carries a tie to that ref for the rest of its life. The refusal above is usually the first
time anybody meets it.
- A trunk kept alive after it merged sits at the past of the trunk it merged into, and
everything cut from it afterwards inherits that. Merging origin/main back in would
settle it, but re-cutting the branch settles the same thing without leaving a merge commit
that carries no work of its own:
```bash
git branch -d dev
git switch -C dev origin/main
```
- Fetch before cutting from a remote-tracking ref.
origin/mainis a local copy of what
the remote held when it was last fetched, and nothing refreshes it on its own. Cut from a
stale one and the trunk stands at a commit the remote has left behind — silently, because
every branch cut from it afterwards inherits that base and the first report of it is the size
of a pull request's diff.
```bash
git fetch origin
git switch -C dev origin/main
```
**Cutting from a local branch does not need the fetch, and does not get the guarantee
either**: a local trunk is as old as the last time somebody moved it.
- A local trunk that is merely behind is advanced by a fetch refspec, not by a checkout.
Naming the branch on both sides of the colon moves the local ref to what the remote holds,
and the form refuses anything that is not a fast-forward — so the one operation these
branches must never take is not available to it.
```bash
git fetch origin <trunk>:<trunk>
```
Standing on another branch while it runs is the point: nothing is checked out, nothing is
merged, and a trunk that has diverged comes back refused rather than silently rebuilt.
- **Merging several sub-branches back is a cycle, not a batch: merge one, rebase the next onto
the trunk's new tip, merge it, rebase the one after that.** Every merge moves the tip, so each
branch is rebased against a commit that did not exist while the branch before it was still
open. Each then merges into the trunk as it now stands, rather than reopening a line that was
already closed.
```bash
git switch <trunk>
git merge --no-ff <first> -m 'Merge …'
git rebase -r <trunk> <second> # onto the tip the merge above just made
git switch <trunk>
git merge --no-ff <second> -m 'Merge …'
git rebase -r <trunk> <third> # onto the tip that merge made
git switch <trunk>
git merge --no-ff <third> -m 'Merge …'
```
- The rebases cannot be done in advance. Aiming them all at one point — the commit the
branches were cut from, or anywhere else — settles nothing past the first merge: the second
branch is behind the tip again by the time its turn comes. The commit each rebase needs does
not exist until the merge before it is made.
- After each rebase and before its merge, confirm the branch still carries something. A
rebase drops a commit whose change the trunk already holds, and where that was the branch's
only commit the branch arrives at the trunk's own tip. The --no-ff merge that follows then
prints Already up to date., exits zero, creates nothing, and **a rung of the structure is
gone** — leaving a graph that reads as one which was never meant to have it.
```bash
git rebase -r <trunk> <branch>
git rev-list --count <trunk>..<branch> # must be greater than zero
```
Measured before it and after it is not the same measurement. Before the rebase the count
was one and would have passed; the rebase took it to zero. The only warning git gave was a
hint about skipped cherry-picks, which -q and a trailing tail both remove.
- This is not the ancestry check above, and neither catches what the other does. A
branch left behind the tip fails --is-ancestor and still makes a merge commit, because
it holds commits of its own. A branch sitting exactly on the tip passes
--is-ancestor — it is not behind anything — and makes none.
- A count of zero is not answered by skipping the merge. The change is in the trunk
already, so the structure was drawn with one rung too many, or the change belongs to a
different sub-branch than the one that carried it. Both are decisions, not repairs.
- The same emptiness arrives by accident wherever a step meant to fill the branch reported
success without committing — a cherry-pick refused for a bad flag, a patch that did not
apply, a copied file identical to the one already there. The check does not care which.
- Two branches are the smallest case of this, not a rule of their own.
- An octopus merge takes the sub-branches in one merge commit instead of the cycle. Where one
is asked for, it is the shape to make, and the cycle is not offered as another reading of the
request.
```bash
git switch <trunk>
git merge --no-ff -m 'Merge …' <merged first> <merged next> <merged last>
```
- An octopus is for branches of equal standing that stand in parallel: independent of one
another, and of one kind. Where several such branches would otherwise be merged one by one,
the octopus is the shape to take, and it shortens the graph. Pieces that are one commit each
and share a reason need neither: they stack in one sub-branch, as `## When the structure is
decided` says. Branches with a dependency between them — one built on another, one that others stand
on — merge one by one, in the order of the dependency.
- Every branch sits on the trunk's current tip before it starts. No tip moves between
merges, so no rebase happens in the middle — but each branch is checked against the tip
first, with --is-ancestor and with a count above zero, exactly as in the cycle.
- The branches are listed by commit count, fewest first, with the smaller diff first among
equal counts, as ### The order the sub-branches merge in says. The first argument sits at
the bottom of the graph and the last on top, and the legs run left to right in the same
order.
- The subject names the whole the trunk gathers, at the altitude of its opening marker,
since one commit now stands for every branch it received.
Carrying a change onto a branch by hand
**A rebase moves a change between branches and keeps a record of what it moved. Writing a file
does neither.** Where an edit was made against one base and is then written onto a branch that
carries its own commits on the same file, whatever those commits added is reverted — and the
revert appears in no diff of its own, because the file simply arrives as the edit left it.
Measured: a file edited against a trunk was about to be written onto a branch carrying six commits
on that same file. Written whole, all six would have been undone, and the commit doing it would
have read as an ordinary update.
So the first act is to read what is already there. Not the file — the two of them against each
other:
git diff <the branch> -- <the path> # what the branch has that the base does not
- Compare the structure, not the text. Which sections the branch holds and the edit does not,
and the reverse. A run of differing lines says the two disagree; a list of section names says
where and why, and it is short enough to check by eye.
- Apply section by section. Take the edit's version where the edit touched a section, and the
branch's version everywhere else. What comes out is the branch's work with the edit laid over
it, which is what writing the file whole was supposed to produce and does not.
- What the edit lacks is not what the branch should lose. A section standing in the branch and
absent from the edit is the branch's own work, and dropping it is the same overwrite arriving by
omission rather than by replacement.
Confirm afterwards by naming what should have survived. The edit's own additions are easy to
see because they are what was just written; the branch's are the ones a wrong application
removes, so those are the ones to look for by name.
What a branch still carries
Whether a branch's work has reached a trunk is not answered by ancestry. --is-ancestor
answers whether the trunk holds those commits, and a branch whose content arrived by another
route — cherry-picked, rewritten, or done again on a different branch — fails that test while
holding nothing the trunk lacks. Measured: a branch reported as not merged turned out to carry no
change the target did not already have.
Three tests answer three different questions, and none of them stands in for another.
| Test | What it answers |
| :-- | :-- |
| git merge-base --is-ancestor <target> <branch> | Whether the trunk holds these very commits |
| git cherry -v <target> <branch> | Which of the branch's patches the target already holds |
| A rebase onto the target | What the branch would actually add |
git cherrymarks an upstream patch-and skips merge commits, so a branch's merges
never appear in its output and a clean run of - is a statement about the non-merge commits
alone.
- A
+is not evidence that anything is missing. A patch id is computed from the change
against its own base, so a commit written on an older base comes out + although the file it
produces is identical to the target's. Measured: two commits marked + left no content
difference at all against the target.
- The rebase is the test that settles it, because what survives it is what the branch adds
and nothing else. Measured on two branches: one of twenty-five commits came out holding three
that carried no change, and one of twenty-one came out holding a single commit.
- Read the direction of a content diff before concluding from its size. A diff against the
target shows what the two differ by, not what the branch contributed: where the target has
moved on, the branch appears to hold work it never touched. Measured: the files filling such a
diff had never been edited on the branch at all.
Deciding a branch may go
**What decides it is what the branch uniquely holds — never its age, its name or how long it has
been open.** Run the tests above, then look at what would be lost with the ref:
- Content. Whatever the rebase leaves is the whole of what the branch adds. Where that is
empty, nothing is lost by deleting it.
- Descendants. A branch something else was cut from is holding that base up, even if it
carries nothing itself.
- A pull request. Deleting the branch closes it, and the discussion on it goes with the
ref rather than with the commits.
- The issue it answers. An issue already closed, or answered by another branch, leaves the
branch with nothing to close.
- Its own base. A branch whose base no longer exists cannot be judged by its diff until it
has been rebased onto something that does.
Where all of these come back empty, the branch is a copy of work that is already elsewhere, and
keeping it costs a reader the time it takes to establish that again.
- A branch whose one unique change nobody wants is in the same position, and the argument
that it might be useful later is answered by how small the change was: writing it again costs
less than rebasing a stale branch onto a base that has moved.
- Delete it with
-dwhere the test allows, and take a refusal as a question rather than
reaching for -D. The refusal is the check described above doing its work.