4

I want to know what are the advantage of --rebase option in git pull command when and where we have to use this option and when we dont have to use this option ?

Nitin9791
  • 1,124
  • 1
  • 14
  • 17
  • 1
    Do you understand how merging works in general? Its probably best you understand that prior to learning how a rebase operation affects the way commits are structured. – Simon Whitehead Dec 03 '15 at 07:21

1 Answers1

3

You should use git pull --rebase when

  • your changes do not deserve a separate branch

Indeed -- why not then? It's more clear, and doesn't impose a logical grouping on your commits.


Ok, I suppose it needs some clarification. In Git, as you probably know, you're encouraged to branch and merge. Your local branch, into which you pull changes, and remote branch are, actually, different branches, and git pull is about merging them. It's reasonable, since you push not very often and usually accumulate a number of changes before they constitute a completed feature.

However, sometimes--by whatever reason--you think that it would actually be better if these two--remote and local--were one branch. Like in SVN. It is here where git pull --rebase comes into play. You no longer merge--you actually commit on top of the remote branch. That's what it actually is about.

Whether it's dangerous or not is the question of whether you are treating local and remote branch as one inseparable thing. Sometimes it's reasonable (when your changes are small, or if you're at the beginning of a robust development, when important changes are brought in by small commits). Sometimes it's not (when you'd normally create another branch, but you were too lazy to do that). But that's a different question.

Link To Follow

Community
  • 1
  • 1
Pankaj Singhal
  • 15,283
  • 9
  • 47
  • 86
  • do I need to add `origin master` to the `--rebase`? I have been seeing that `git pull --rebase` is just sufficient. – Mohammad Faisal Apr 30 '20 at 09:41
  • 3
    if you don't specify & then it will try to use the default tracking remote/branch. Generally `origin master` is already the tracking branch of master. Hence, you don't need that there – Pankaj Singhal Apr 30 '20 at 12:24