When to use git pull --rebase

Posted by Daniel on Monday, February 20, 2023

When the tip of your local branch is behind he remote branch, you can’t push to orgin. This happens if you pulled and worked in a branch, made some changes and commited them, while someone else have made changes and pushed them to origin.

Solution

To solve this you could use git pull which pulls the origin branch to your local branch but will create an unnecessary merge commit.

What I prefer though, is to use git pull --rebase instead. This will rebase your local branch by adding your local commits on top of the remote commits, and after this you’re able to push to origin again


comments powered by Disqus