0

I'm just wondering what are more reasons to use git pull --rebase instead of git pull except this weird merge commits that appear when you do just git pull? Thanks!

Kosmetika
  • 20,774
  • 37
  • 108
  • 172
  • Where you want your own local commits to be applied on top of the public history - have you done any research for your question? – AD7six Jun 20 '14 at 10:00
  • 2
    It's better to use `fetch` + `merge` – zerkms Jun 20 '14 at 10:00
  • 3
    http://stackoverflow.com/questions/804115/git-rebase-vs-git-merge?rq=1 – Thilo Jun 20 '14 at 10:01
  • @zerkms you probably meant fetch + rebase given the question. It's not "pull v fetch+merge" but "rebase v merge" – AD7six Jun 20 '14 at 10:02
  • I meant ``git fetch`` and then ``git pull --rebase`` I worked with my collegues on one branch with small updates, and it works fine – Kosmetika Jun 20 '14 at 10:07
  • @AD7six: nope, `fetch` + `merge`. `Rebase` may cause controversial automatic merges which you won't be able to explain after. http://chat.stackoverflow.com/transcript/52638/2014/5/14/1-3 --- here is a discussion where I provided a proof for what I'm talking about – zerkms Jun 20 '14 at 10:08
  • @zerkms so your answer to "why/when is it better to pull --rebase instead of git pull" is "Don't use rebase ever"? That conversation is too long to see whatever it is you're trying to point out - but I disagree that rebase has no place in git (which is how I read your last comment). – AD7six Jun 20 '14 at 10:12
  • @AD7six As I understand ``merge`` will produce additional commit – Kosmetika Jun 20 '14 at 10:13
  • @Kosmetika yes it will. That's not the only difference, or even the main difference though. – AD7six Jun 20 '14 at 10:13
  • @AD7six: that's correct - my answer for the given question is "Please don't, use `fetch` + `merge` instead". As I said, `rebase` may cause the output that no one will be able to explain, unless you know it might be introduced by a `rebase`, which is not the case since there are no traces of `rebase` after it's done. – zerkms Jun 20 '14 at 10:14
  • @AD7six in my experience ``fetch`` and ``git pull --rebase`` worked fine all the time, any unexpected conflicts etc. – Kosmetika Jun 20 '14 at 10:15

1 Answers1

2

git pull is really just shorthand for

git fetch
git merge

Now, if you your branch has changed independent of the upstream version you are pulling, the history of your branch will now have branching in it (use gitk for a simple visualization).

However, if you use git pull --rebase, git will try to rebase your changes on top of the changes from the upstream source, retaining a linear commit history, which is generally preferable for clarity and other git history manipulations.

Arne Claassen
  • 14,088
  • 5
  • 67
  • 106