# Git Rebase

## Rebasing a feature branch from main

On occassion you'll find that you've been working on a feature branch and you need to merge in changes from main. This could just be a final step before you push a series of commits to github before creating a PR.

These steps are similar to what the "Rebase and Merge" action does on github.

### Objective

This guide will show you how to rebase (rebuild) a feature branch to begin at the current HEAD of the main branch. Think of it as if you are starting a new branch based on the current main and pasting all of your commits to the new branch.

![](/files/-MG13iTglI6Yxny_aw_3)

{% hint style="danger" %}
Never rebase a branch that has already been pushed to a remote (public, eg. the main branch) repository, such as github; doing so will cause conflicts and confusion among your team.
{% endhint %}

#### Technologies

* git cli

#### References

* [The Pro Git book](https://git-scm.com/book/en/v2/Git-Branching-Rebasing)
* [bitbucket tutorials](https://www.atlassian.com/git/tutorials/rewriting-history/git-rebase)

### Getting Started

1. Make sure all changes are committed to your feature branch
2. You will need to update your local main branch
   * `> git checkout main`
   * `> git pull origin main`
3. Go back to your feature branch
   * `> git checkout feature-branch`
4. Now we can rebase the feature branch onto `main`

   > git rebase main First, rewinding head to replay your work on top of it... Applying: added staged command
5. Your commits will now show in the git log after the commits merged from main


---

# 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://bloomtechlabs.gitbook.io/guides/coding/git-rebase.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.
