
Rebase Downstream
- 7 installs
- 3.5k repo stars
- Updated August 6, 2026
- brave/brave-core
rebase-downstream is a Claude Code skill that rebases a tree of dependent branches after upstream changes, running preflight checks on each branch in order.
About
Rebases a tree of dependent branches after upstream changes. It auto-detects the downstream branch chain including siblings, rebases each branch onto its parent with --fork-point, resolves conflicts where possible, and runs preflight checks on every branch. A developer uses it to propagate changes through a stack of feature branches.
- Auto-detects the downstream branch tree including siblings
- Rebases each branch with git rebase --fork-point in order
- Runs full preflight on every branch and stops on any failure
Rebase Downstream by the numbers
- 7 all-time installs (skills.sh)
- Ranked #456 of 732 Git & Pull Requests skills by installs in the Skillselion catalog
- Data as of Aug 6, 2026 (Skillselion catalog sync)
rebase-downstream capabilities & compatibility
Free; runs against a local git checkout.
- Capabilities
- refactoring · testing
- Use cases
- refactoring
- Runs
- Runs locally
- Pricing
- Free
What rebase-downstream says it does
Rebase a tree of dependent branches after upstream changes have been made. Auto-detects the downstream branch tree (including sibling branches), rebases each branch in order, resolves conflicts when p
Do not force-push any branches — the user will decide when to push
npx skills add https://github.com/brave/brave-core --skill rebase-downstreamAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 7 |
|---|---|
| repo stars | ★ 3.5k |
| Last updated | August 6, 2026 |
| Repository | brave/brave-core ↗ |
What it does
Rebase a chain or tree of dependent branches after upstream changes and validate each with preflight.
Who is it for?
Developers maintaining a stack of dependent feature branches that need to follow an upstream change.
Skip if: Force-pushing branches, which it deliberately leaves to the developer.
When should I use this skill?
An upstream branch changed and its downstream branch chain needs rebasing.
What you get
Every downstream branch is rebased onto its parent and passes preflight, or the run stops at the first failure.
By the numbers
- 6-step process
- depth-first pre-order rebase of the branch tree
Files
Rebase Downstream Tree
Rebase a tree of dependent branches after upstream changes have been made. Auto-detects the downstream branch tree (including sibling branches), rebases each branch in order, resolves conflicts when possible, and runs preflight checks on each branch.
Current State
- Branch: !
git branch --show-current - Status: !
git status --short
Steps
1. Detect current branch
Get the current branch name. This is the branch that was just modified and whose changes need to propagate downstream.
git branch --show-current2. Auto-detect downstream chain
Run the detect-chain.sh helper script to find all downstream branches:
bash .claude/skills/rebase-downstream/detect-chain.sh <current-branch>The script outputs branch:parent per line in rebase order (depth-first pre-order). This handles both linear chains and trees with sibling branches.
3. Confirm the chain
Display the detected chain to the user and ask for confirmation before proceeding.
If no downstream branches are detected, report this to the user and stop.
If branches are detected, show the tree visually:
<current-branch>
→ <child1>
→ <grandchild1>
→ <child2> (sibling)Ask the user to confirm before rebasing. If the user declines, stop.
4. Rebase each branch in order
For each downstream branch (closest to the current branch first):
1. Checkout the branch:
git checkout <downstream-branch>2. Rebase onto its parent (from the branch:parent output):
git rebase --fork-point <parent-branch>--fork-point uses the parent branch's reflog to find the actual fork point, so only the branch's own commits are replayed. Without it, if the parent was rebased/amended, git replays already-applied parent commits with different SHAs, causing duplicate commits and false conflicts.
The parent for each branch is provided by the detect script. For sibling branches, both share the same parent.
3. Handle conflicts (if any):
- Inspect each conflicted file to understand both sides
- Attempt to resolve the conflict intelligently
- After resolving, stage the files and continue:
git add <resolved-files>
git rebase --continue- If a conflict cannot be resolved, abort and stop:
git rebase --abortReport which branch and files had unresolvable conflicts, then stop entirely. Do NOT continue to the next branch.
4. Run full preflight checks using /preflight on this branch. This includes format, gn_check, presubmit, build, and tests. If preflight fails, stop and report. Do NOT continue to the next branch.
5. Move to the next branch only after successful rebase and preflight.
5. Return to the original branch
After all branches are rebased successfully, checkout the original starting branch:
git checkout <original-branch>6. Report results
Summarize the results:
- Rebased branches: List each branch that was successfully rebased
- Conflicts resolved: Note any conflicts that were auto-resolved and how
- Preflight results: Summary of preflight status for each branch
- Tree: Show the full rebased tree structure
Important
- NEVER skip preflight checks on any branch in the chain
- Stop immediately if a rebase conflict cannot be resolved
- Stop immediately if preflight fails on any branch
- Always return to the original branch at the end (even on failure)
- Do not force-push any branches — the user will decide when to push
#!/usr/bin/env bash
# Copyright (c) 2026 The Brave Authors. All rights reserved.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at https://mozilla.org/MPL/2.0/.
#
# detect-chain.sh - Detect downstream branch tree from a starting branch.
#
# Usage: detect-chain.sh [starting-branch]
#
# Outputs "branch:parent" per line in rebase order (depth-first pre-order).
# Handles trees with sibling branches (forks).
#
# Compatible with bash 3+ (no associative arrays).
set -euo pipefail
start_branch="${1:-$(git branch --show-current)}"
if [[ -z "$start_branch" ]]; then
echo "Error: No branch specified and not on a branch." >&2
exit 1
fi
# Use temp files to store parent and children maps (bash 3 compat)
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
parent_dir="$tmpdir/parents"
children_dir="$tmpdir/children"
mkdir -p "$parent_dir" "$children_dir"
# Sanitize branch name for use as filename (replace / with __)
sanitize() {
echo "$1" | sed 's|/|__|g'
}
set_parent() {
local branch="$1" parent="$2"
echo "$parent" > "$parent_dir/$(sanitize "$branch")"
}
get_parent() {
local f="$parent_dir/$(sanitize "$1")"
[[ -f "$f" ]] && cat "$f" || true
}
has_parent() {
[[ -f "$parent_dir/$(sanitize "$1")" ]]
}
add_child() {
local parent="$1" child="$2"
echo "$child" >> "$children_dir/$(sanitize "$parent")"
}
get_children() {
local f="$children_dir/$(sanitize "$1")"
[[ -f "$f" ]] && cat "$f" || true
}
# Collect all local branches
all_branches=$(git for-each-ref --format='%(refname:short)' refs/heads/)
# is_ancestor_of: check if $1 (or any historical tip of $1) is an
# ancestor of $2. Handles rebased branches by walking the reflog.
is_ancestor_of() {
local ref="$1" target="$2"
if git merge-base --is-ancestor "$ref" "$target" 2>/dev/null; then
return 0
fi
# Fallback: if the local branch was rewritten (e.g., rebased with new
# hashes), the old commits still exist on origin/<branch>.
if git show-ref --verify --quiet "refs/remotes/origin/$ref" 2>/dev/null; then
if git merge-base --is-ancestor "origin/$ref" "$target" 2>/dev/null; then
return 0
fi
fi
# Fallback: walk the reflog of $ref to find old tips that are still
# ancestors of $target. This catches cases where both local and origin
# have been rebased (new commits) but the downstream branch still has
# the old commits.
#
# IMPORTANT: Skip reflog entries that are ancestors of the current tip.
# After "git reset --hard <base> && git commit", the base SHA appears
# in the reflog and is an ancestor of every branch, causing every
# local branch to be falsely detected as a descendant. Only entries
# representing rewritten-away history (old tips not reachable from the
# current tip) should be checked.
local ref_tip old_sha
ref_tip=$(git rev-parse "$ref" 2>/dev/null) || return 1
while IFS= read -r old_sha; do
[[ -z "$old_sha" ]] && continue
# Skip if this SHA is reachable from current tip (not rewritten-away)
if git merge-base --is-ancestor "$old_sha" "$ref_tip" 2>/dev/null; then
continue
fi
if git merge-base --is-ancestor "$old_sha" "$target" 2>/dev/null; then
return 0
fi
done < <(git reflog show "$ref" --format='%H' 2>/dev/null \
| awk '!seen[$0]++' | head -50)
return 1
}
# Find all descendant branches of start_branch using ancestor checks.
descendants=()
for branch in $all_branches; do
[[ "$branch" == "$start_branch" ]] && continue
if is_ancestor_of "$start_branch" "$branch"; then
descendants+=("$branch")
fi
done
# For each descendant, find its closest parent among start_branch + other
# descendants. The closest parent is the one whose HEAD is an ancestor of
# the branch AND is not an ancestor of any other ancestor candidate.
for branch in "${descendants[@]+"${descendants[@]}"}"; do
closest_parent="$start_branch"
for other in "${descendants[@]+"${descendants[@]}"}"; do
[[ "$other" == "$branch" ]] && continue
# If other is an ancestor of branch AND other is a descendant of
# our current closest_parent, then other is a closer parent.
if is_ancestor_of "$other" "$branch" && \
is_ancestor_of "$closest_parent" "$other"; then
closest_parent="$other"
fi
done
set_parent "$branch" "$closest_parent"
done
# Build children map from parent map
for f in "$parent_dir"/*; do
[[ -f "$f" ]] || continue
branch=$(basename "$f" | sed 's|__|/|g')
parent=$(cat "$f")
add_child "$parent" "$branch"
done
# Walk the tree starting from start_branch (depth-first pre-order)
walk_tree() {
local current="$1"
local kids
kids=$(get_children "$current")
if [[ -z "$kids" ]]; then
return
fi
# Read children into an array
local kid_array=()
while IFS= read -r k; do
[[ -n "$k" ]] && kid_array+=("$k")
done <<< "$kids"
# Visit each child and recurse (parents always before children)
for child in "${kid_array[@]}"; do
echo "$child:$current"
walk_tree "$child"
done
}
walk_tree "$start_branch"