Git merge vs rebase: merge preserves history as-is, rebase linearizes it

Ever wondered how to clean up messy code history?

Image: Carol M. Highsmith, Public domain, via Wikimedia Commons

Git merge vs rebase: merge preserves history as-is, rebase linearizes it

Ever wondered how to clean up messy code history?

Imagine you're tidying up your messy room after a big party, with clothes and toys scattered everywhere. You want to put everything back in order without losing any items.

Think of Git merge as putting all toys back into their boxes, keeping all toys and clothes as they were. Rebase is like straightening clothes on the floor before putting them back in boxes, making everything look tidy but changing the order.

Example

You have a toy box (merge) with toys from last year (old commits) and this year (new commits) together. If you rebase, you first put this year's toys (new commits) on the floor (linearize history) before putting them back into the toy box (rebase commits).

Remember this

Merge keeps history intact, rebase creates a cleaner, linear history.

Related concepts

Swipe through 100 ML concepts daily

Open Pocket Polymath