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

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)!

Oldest comments (2)

Collapse
 
v6 profile image
Info Comment hidden by post author - thread only accessible via permalink
πŸ¦„N BπŸ›‘

Most of what people need when they do a git pull is met by the execution of a git pull --rebase.

More on this, and the practical implications of using it with other people, here:

sandofsky.com/workflow/git-workflow/

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.

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