4

What exactly happens when I run the command

git pull --rebase on master branch

Does this rewrite my master branch history

Is it a good way to pull changes or should we

 1. Git fetch 
 2. Git merge
Nandish A
  • 1,645
  • 5
  • 26
  • 41
  • 1
    possible duplicate of [git rebase vs git merge](http://stackoverflow.com/questions/804115/git-rebase-vs-git-merge) – Joe Jul 04 '14 at 11:30
  • `rebase` ensures a linear history contrary to `merge`. It's a good idea to `rebase` when you want to have a cleaner history for one. – gravetii Jul 04 '14 at 11:53

1 Answers1

2

When you git pull --rebase, a few things happen:

  1. git fetch origin master

    -just using origin/master as an example

  2. git rebase origin/master

    • moves all of your commits after the commits on origin/master

At this point, you can now push to origin and your commits will be applied on top of all other commits cleanly.

Without the --rebase flag, you'd end up with a merge commit; one that has two parents: your master branch and the work on origin/master

Here are a few helpful resources:

  1. http://viget.com/extend/only-you-can-prevent-git-merge-commits
  2. http://gitready.com/advanced/2009/02/11/pull-with-rebase.html
jshawl
  • 3,315
  • 2
  • 22
  • 34