Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git pull --rebase vs git rebase : what's the danger?

I don't understand the difference between git pull --rebase and git rebase, without any other options.

I don't understand if they are safe, a good practice, or very dangerous.

Can I break the history of commits by doing a git pull --rebase in local?

like image 255
sab Avatar asked Jun 24 '16 15:06

sab


People also ask

Is git pull rebase safe?

Not necessarily safe, git pull --rebase can actually lose commits it tried to rebase if it fails.

Is rebase risky?

Rebasing can be dangerous! Rewriting history of shared branches is prone to team work breakage. This can be mitigated by doing the rebase/squash on a copy of the feature branch, but rebase carries the implication that competence and carefulness must be employed.

Should I use git pull or git rebase?

git pull --rebase may hide a history rewriting from a collaborator git push --force . I recommend to use git pull --rebase only if you know you forgot to push your commits before someone else does the same. If you did not commit anything, but your working space is not clean, just git stash before to git pull .

Why you should avoid git rebase?

Case 1: We should not do Rebase on branch that is public, i.e. if you are not alone working on that branch and branch exists locally as well as remotely rebasing is not a good choice on such branches and it can cause bubble commits.


2 Answers

I don't recommend rebasing at all but just for private branches. By private I mean branches that you're pretty sure only you have pulled.

A rebase changes the starting point of the branch to some newer commit, thus merging all the commits to that point. This could lead to merge conflicts to people that had in their repository the old branch base. I would recommend plain merge always and leave rebasing only for certain situations (feature branches, for example).

Regarding your question:

  • git rebase rebases the branch you want.
  • git pull --rebase performs a fetch + rebase in the branches you pull. Normally a pull would fetch + merge.
like image 166
Luis Avatar answered Oct 06 '22 13:10

Luis


git pull --rebase is a shorthand for git fetch and then a plain git rebase, as opposed as to the default git merge. The practical difference is that applying only the latter would not fetch any new commits from your remote prior to rebasing your code on top of, as it would only take into account what your local repository's already aware of.

It's also worth mentioning that merging conflicts would appear in the same way as a regular git pull.

like image 38
everton Avatar answered Oct 06 '22 14:10

everton