1

I'm understanding the difference between a git fetch and git pull (the former leaves local branch untouched, the latter merges changes into local branch), but I'm bit confused about this cheat sheet:

enter image description here

There is an arrow directly underneath "fetch", which makes it look like fetch and pull are identical functions. From what I understand, only the bottom-most arrow should be "pull". Does anyone else agree that the arrow below "fetch" shouldn't be there? If it should, can you please explain why?

Pankaj Singhal
  • 15,283
  • 9
  • 47
  • 86
Andy
  • 71
  • 1
  • 5
  • Until quite recently, `git pull` was a shell script that literally ran `git fetch` first, then ran `git merge` (or if you say so, `git rebase`) after the fetch finished. It still works like that internally. NZD's answer, that `pull` effectively labels *both* arrows, is hence the best one. The cheat-sheet is not literally correct though, as the merge-or-rebase step itself is purely local. My recommendation to Git newbies is to *avoid* `git pull` as much as possible: just use the two underlying commands. – torek Aug 12 '18 at 06:33

4 Answers4

2

Pull belongs to both arrows (the ones it borders). Pull includes a fetch; it updates your local repository (same as fetch) and it also updates your local workspace.

NZD
  • 1,780
  • 2
  • 20
  • 29
2

What it is trying to say with the arrow beneath the fetch is that when you do a pull, you update both the local repo as well as the workspace. Hence, a pull both for local repo & workspace.

A git pull is basically a git fetch & git merge.

Here is Oliver Steele's image of how all it all fits together:

enter image description here

Link to follow.

Pankaj Singhal
  • 15,283
  • 9
  • 47
  • 86
0

Both fetch and merge sync remote repo to local repo which is what diagram conveys. So its correct as per diagram. As you mentioned, former don't merge and later merge is after syncing to local repo.

Dinesh Balasubramanian
  • 20,532
  • 7
  • 64
  • 57
0

From git docs:

Incorporates changes from a remote repository into the current branch. In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD. More precisely, git pull runs git fetch with the given parameters and calls git merge to merge the retrieved branch heads into the current branch. With --rebase, it runs git rebase instead of git merge.

So git pull do two work first git fetch and second git merge. Fetch update your local repository and merge update your working directory. So both arrows represent pull is fine.

mastisa
  • 1,875
  • 3
  • 21
  • 39