5

I know the difference between git pull and git fetch .

but i want to know, Which one is Preferable?

because git pull doing merge automatically without my knowledge. thats the different i found. git fetch wont do that. is there anything else?

Mohideen bin Mohammed
  • 18,813
  • 10
  • 112
  • 118
  • totally different things that are used for totally different actions on your git controlled project.... – ΦXocę 웃 Пepeúpa ツ Jun 23 '17 at 09:36
  • They are completely different commands. GIt pull is actually fetch + merge(more or less). – Lemonov Jun 23 '17 at 09:36
  • 1
    `git pull` does `git fetch` and `git merge` together – Omri Luzon Jun 23 '17 at 09:37
  • Which one do you prefer? – axiac Jun 23 '17 at 09:40
  • pull will do merge automatically . but there is possibility of generating new commits. in fetch , people might forgot to merge and start to do some task . thats why .. i am confused which one should i follow – Mohideen bin Mohammed Jun 23 '17 at 09:41
  • https://stackoverflow.com/questions/292357/what-is-the-difference-between-git-pull-and-git-fetch?noredirect=1&lq=1 is the best place where you can find your answer – Suryakant Sharma Jun 23 '17 at 09:44
  • Personally I prefer `git fetch`. If you know what `git pull` can do and what it will do, with kinds of options, it's a convenient command. But so far as I've observed, quite some people use it blindly and mess the local repo up, which is quite frustrating. – ElpieKay Jun 23 '17 at 11:34
  • 3
    Possible duplicate of [What is the difference between 'git pull' and 'git fetch'?](https://stackoverflow.com/questions/292357/what-is-the-difference-between-git-pull-and-git-fetch) – Cody Gray - on strike Jun 27 '17 at 12:04

2 Answers2

8

Contrary to the above comments, git pull and git fetch are not completely different commands. Rather, doing a git pull on a given branch is the same as doing a git fetch followed by either merging or rebasing the current branch on its remote counterpart which was just updated.

The utility of doing a git pull is that often the reason we fetch is to update a local branch with the version on the remote. So it is a bit of a convenience. We can always do fetch followed by merge separately.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
7

git pull will do a git fetch and then a git merge. So it depends what do you want to do.

If you prefer to handle manually the merge you shouldn't use git pull

What is the difference between 'git pull' and 'git fetch'?

Till
  • 4,183
  • 3
  • 16
  • 18
  • 1
    `merge` or `rebase`, according to your configuration. – Ealhad Jun 23 '17 at 09:39
  • i said i know the difference but my question is which one is preferable? pull will do merge without knowledge which is faster than fetch. but there is possibility of generating new commits. in fetch , people might forgot to merge and start to do some task . thats why – Mohideen bin Mohammed Jun 23 '17 at 09:40