简体   繁体   中英

Git: fetch vs. pull, in the context of this Git cheat sheet

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:

在此处输入图片说明

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?

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.

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 :

在此处输入图片说明

Link to follow.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM