git pull --rebase
This command fetches changes from an upstream repository, and then applies the current branch's commits on top of these new changes.
It is useful when you want to make sure your local commits are based on the latest version of the branch in the upstream repository. Essentially, it helps you keep your commit history clean and easy to understand, as there won't be any merge commits showing changes that were pulled in from the upstream repository. The command is valid for both local and remote repositories.
The --rebase
flag can be replaced by -r
for a shorter version. There is also the --rebase=interactive
or -ri
for an interactive rebase, which allows you to edit, squash or reorder your commits before they are applied on top of the fetched changes.