DEV Community

Cover image for Don't git pull, use git pull --rebase instead
Emmanouil Liakos
Emmanouil Liakos

Posted on β€’ Originally published at blog.manos-liakos.dev

11 5

Don't git pull, use git pull --rebase instead

Here is another quick post about a neat thing I recently learned.

Git pull

What git pull will actually do behind the scenes, is git fetch & git merge. It will fetch changes from the remote and create a new merge commit.

Git pull --rebase

What git pull --rebase will do, is git fetch & git rebase, effectively reapplying our local changes on top of the remote changes, resulting in a tidy, linear commit history, like this:

rebased_history_line

Quick tips

Tip #1: Use git config --global pull.rebase true to avoid typing the --rebase flag each time you pull 🧐

Tip #2: Don't forget that you can do all sorts of editing to your commits, before pushing them by using interactive rebase.

git rebase -i
Enter fullscreen mode Exit fullscreen mode

You can check more about this in my other post about useful git commands.

Warning: Use rebase only on local branches, as it rewrites commit history (creates new commits)!

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (2)

Collapse
 
adewitt76 profile image
Aaron DeWitt β€’

Sharing this articles with my coworkers...

We had all been pushing and merging which when trying to decipher what is what on a graph we had several masters and it was hard to follow.

Thanks for the article.

Collapse
 
v6 profile image
πŸ¦„N BπŸ›‘ β€’
Comment hidden by post author

Some comments have been hidden by the post's author - find out more

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Best practices for optimal infrastructure performance with Magento

Running a Magento store? Struggling with performance bottlenecks? Join us and get actionable insights and real-world strategies to keep your store fast and reliable.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❀️