# git rebase-onto

## Problem

You have a branch `feature-a`. You finish it and submit it for review, and then branch off of `feature-a` to start working on `feature-b` which depends on your latest changes.

Your code is reviewed and some changes are requested. You update `feature-a`, push, and merge. You want to keep `feature-b` up to date, so you check it out and run `git rebase origin/master`. However, your latest revisions lead to a self merge conflict when trying to rebase `feature-b` off of master.

```
# Before code review
# origin/master
master
# feature-a
master -> feature-a
# feature-b
master -> feature-a -> feature-b

# After code review
# origin/master (using master as parent for consistency, though HEAD is now feature-a')
master -> feature-a' # revised feature-a is now HEAD
# feature-b (feature-a conflicts with feature-a')
master -> feature-a -> feature-b
```

## Solution

Instead of `git rebase origin/master`, use `git rebase --onto origin/master feature-a`.

Specifically, this means "take all commits that are on top of `feature-a`, and place them on top of `origin/master`'s `HEAD`." In the common scenario where `feature-a` is the only difference between `origin/master` and `feature-b`, it can be thought of as "drop all changes between `origin/master`'s `HEAD` and `feature-a` inclusive."


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://timhwang21.gitbook.io/index/cli/git/git-rebase-onto.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
