3

Does git pull always create a merge commit?

If I have a feature branch that I bring up to date with git pull -r . master, and then I switch to master and do git pull . feature-branch I don't think I get a merge commit.

Ben Aston
  • 53,718
  • 65
  • 205
  • 331
  • 1
    `git pull` can fast-forward. – MicroVirus Jun 09 '16 at 11:07
  • Okay so when it fast-forwards, it results in no merge commit? So I need to use the --no-ff flag to force a merge commit if I want one? – Ben Aston Jun 09 '16 at 11:07
  • 3
    Yes, the description of the `-ff` (fast-forward) flag says: *"When the merge resolves as a fast-forward, only update the branch pointer, without creating a merge commit. This is the default behavior."* – MicroVirus Jun 09 '16 at 11:08
  • Using the `--rebase` flag changes things a bit (I'm not sure about how it works tbh), but it still shouldn't create a merge commit by default I'd think. Don't take my word for it, though. – MicroVirus Jun 09 '16 at 11:13
  • I would like to see an answer that compares different ways of doing `git pull` (default, `-no-ff`, `--rebase`, etc.). – Emil Laine Jun 09 '16 at 11:22
  • @tuple_cat : I added the --rebase option in my answer – Flows Jun 10 '16 at 06:56

1 Answers1

4

You have a good example about git merge and fast-forward on the linked website.

@MicroVirus gave a nice explanation. Below, the grey point is the HEAD of your local HEAD before the pull (fetch + merge). You can see the difference between the two way to merge.

git fast forward
(source: ofilabs.com)

Another way to update your repo with git pull is to use --rebase option. This option apply your commits on the top of the pulled branch rewriting the history. You can read details there. People are divided between using git pull or git pull --rebase. To my mind, the rebase should be use for bug fix instead classic pull should be use when a new feature is merged to master.

Git rebase example git rebase example

Read the link bellow to have an idea on differents point of view :

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Flows
  • 3,675
  • 3
  • 28
  • 52