Git study notes: the difference between fork and clone, the difference between fetch and pull

 This article is transferred from: http://blog.sina.com.cn/s/blog_4a0824490102wf5y.html Author: ccpacer

fork: On the github page, click the fork button. Copy someone else's repository to your own repository.

clone: ​​clone the repository in github to your local computer

 

Question: The role of pull request

For example, on the premise that the owner of the warehouse (A) did not add us as a project collaborator, we clone a warehouse named "a" in A's warehouse to our own computer, and modify it on our own computer, but we You will find that we can't contribute code to B through push.

 

So to contribute your code to B, we should:

  1. Fork project a in A's warehouse (at this time, our own github has an identical warehouse a, but the URL is different)
  2. Push our modified code to warehouse B in our github
  3. pull request , the master will receive the request and decide whether to accept your code or not
  4. You can also apply as a contributor to project a, so you can push directly
(2) After forking other people's projects to their own repository, other people's projects are updated, how to update our fork projects?
A: First, fetch the online updates to your own project, and then judge and merge. Here comes the next question, what is the difference between pull and fetch.
 
(3) fetch+merge has the same effect as pull. But use fetch+merge more, so that you can check whether the updates from fetch are appropriate. Pull directly includes these two steps. If you think there is no problem with online updates, you can also pull directly.
 
references:
1 http://www.tech126.com/git-fetch-pull/
3 https://ruby-china.org/topics/15729
 
==================================================

1. git fetch: It is equivalent to getting the latest version from the remote to the local, it will not automatically merge
    
git fetch origin master
git log -p master..origin/master
git merge origin/master

    The meaning of the above command:
   first download the latest version from the master branch of the remote origin to the origin/master branch,
   then compare the difference between the local master branch and the origin/master branch, and
   finally merge

   The above process can actually be carried out in the following clearer ways:
   
git fetch origin master:tmp
git diff tmp 
git merge tmp

    
    Get the latest version from the remote to the local test branch and
   then compare and merge

2. git pull: equivalent to getting the latest version from the remote and merge to the local
   
git pull origin master

    The above commands are actually equivalent to git fetch and git merge
    . In actual use, git fetch is safer
   because we can check the update before merging, and then decide whether to merge or not.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324817162&siteId=291194637