> For the complete documentation index, see [llms.txt](https://jadelab.gitbook.io/jadegit/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jadelab.gitbook.io/jadegit/0.18.0/developers/branches/rebase.md).

# Rebase

Rebase is not currently supported directly by JadeGit.

To rebase your current branch, the following steps outline how to perform the operation externally using a Git client of your choice.

{% stepper %}
{% step %}

### Push

Push the current branch to the remote repository from JadeGit.
{% endstep %}

{% step %}

### Clone

If the repository has not been cloned externally yet, clone it into a folder of your choice:

```powershell
git clone <repository-url> <path>
```

Otherwise, when using an existing clone, fetch the latest changes:

```powershell
git fetch
```

{% hint style="success" icon="lightbulb" %}
If your system contains entities whose names differ only by case, [enable case sensitivity](https://learn.microsoft.com/en-us/windows/wsl/case-sensitivity) on the folder before cloning by running the following command as an administrator:

```powershell
fsutil.exe file setCaseSensitiveInfo <path> enable
```

{% endhint %}
{% endstep %}

{% step %}

### Switch

Switch to the branch to be rebased:

```
git switch <branch>
```

When using an existing clone and the branch has been checked out previously, use the pull command to ensure it is up-to-date:

```powershell
git pull
```

{% endstep %}

{% step %}

### Rebase

Rebase the branch onto the target branch using one of the following commands, depending on the scenario.

<details>

<summary>Update</summary>

Use `git rebase` when the branch has fallen behind its base and needs to be brought up to date:

```powershell
git rebase <target-branch>
```

For example, given `feature` has fallen behind `main` since branching:

```mermaid
gitGraph
   commit id: "A"
   commit id: "B"
   branch feature
   checkout feature
   commit id: "C"
   commit id: "D"
   checkout main
   commit id: "E"
   commit id: "F"
```

Running the following rebases `feature` onto the tip of `main`:

```powershell
git rebase main
```

`C` and `D` are replayed on top of `F` as `C'` and `D'`, giving `feature` a linear history from the tip of `main`:

```mermaid
gitGraph
   commit id: "A"
   commit id: "B"
   commit id: "E"
   commit id: "F"
   branch feature
   checkout feature
   commit id: "C'"
   commit id: "D'"
```

</details>

<details>

<summary>Transplant</summary>

Use `git rebase --onto` when the original base branch has been rewritten, or when rebasing onto a branch other than the one the current branch was created from:

```
git rebase --onto <new-base> <old-base>
```

For example, given `feature` was branched from the `original` main branch, but needs to be rebased onto `main` which has been rewritten:

<pre class="language-mermaid"><code class="lang-mermaid"><strong>gitGraph
</strong>   commit id: "A"
   commit id: "B"
   branch original
   checkout original
   commit id: "C"
   commit id: "D"
   branch feature
   checkout feature
   commit id: "E"
   commit id: "F"
   checkout main
   commit id: "C'"
   commit id: "D'"
</code></pre>

Running the following rebases `feature` onto `main`, using `original` as the old base (a commit id may be used instead where the old base branch has been rewritten or no longer exists):

```powershell
git rebase --onto main original
```

`E` and `F` are replayed onto `D'` as `E'` and `F'`, with `feature` now based directly on `main` rather than `original`:

```mermaid
gitGraph
   commit id: "A"
   commit id: "B"
   branch original
   checkout original
   commit id: "C"
   commit id: "D"
   checkout main
   commit id: "C'"
   commit id: "D'"
   branch feature
   checkout feature
   commit id: "E'"
   commit id: "F'"
```

</details>

Once complete, push the rebased branch back to the remote repository:

```powershell
git push origin <branch> --force-with-lease
```

{% endstep %}

{% step %}

### Reset

In JadeGit, fetch the updated branch from the remote repository.

Using the **Manage Branches** option, navigate to the remote branch to view the rebased commit history. Select the last commit and use the [reset](/jadegit/0.18.0/developers/branches/reset.md#delete-changes-hard) option in the context menu to update the current branch to match.
{% endstep %}
{% endstepper %}
