# What Rebase Does — Git Fundamentals: Commits, Branches and Collaboration

Source: https://www.skillbyai.com/en/git/git-rebase-basics

> Replay your commits on a new base with git rebase, and know why you never rebase shared branches.

## Rebase onto main

This replays your branch's commits on top of the latest `main`, one by one, instead of creating a merge commit.

```bash
git switch feature/login
git rebase main
```

Output:

```
Successfully rebased and updated refs/heads/feature/login.
```

## Rebase vs merge

Merge preserves history exactly as it happened, with branches visible. Rebase **rewrites** commit history into a straight, linear line — cleaner to read, but the commits get new hashes.

## Never rebase shared history

Since rebase rewrites commits, never rebase a branch that others have already pulled — it forces everyone to fix their history. Rebase only your own unpushed local work.
