What is the difference between pull and clone in git?

匿名 (未验证) 提交于 2019-12-03 01:25:01

问题:

What is the difference between doing (after mkdir repo and cd repo):

git init git remote add origin git://github.com/cmcculloh/repo.git git fetch --all git pull origin master 

and

git clone git://github.com/cmcculloh/repo.git 

I mean, obviously one is shorter, but other than that are they basically doing the same thing?

回答1:

They're basically the same, except clone will setup additional remote tracking branches, not just master. Check out the man page:

Clones a repository into a newly created directory, creates remote-tracking branches for each branch in the cloned repository (visible using git branch -r), and creates and checks out an initial branch that is forked from the cloned repository's currently active branch.



回答2:

git clone is how you get a local copy of an existing repository to work on. It's usually only used once for a given repository, unless you want to have multiple working copies of it around. (Or want to get a clean copy after messing up your local one...)

git pull (or git fetch + git merge) is how you update that local copy with new commits from the remote repository. If you are collaborating with others, it is a command that you will run frequently.

As your first example shows, it is possible to emulate git clone with an assortment of other git commands, but it's not really the case that git pull is doing "basically the same thing" as git clone (or vice-versa).



回答3:

In laymen language we can say:

  • Clone: Get a working copy of the remote repository.
  • Pull: I am working on this, please get me the new changes that may be updated by others.


回答4:

Git clone means you are making a copy of the repository in your system. Git fork means you are copying the repository to your Github account. Git pull means you are fetching the last modified repository. Git push means you are returning the repository after modifying it.

In Layman's term Git clone is downloading and Git pull is refreshing.



回答5:

Hmm, what's missing to see the remote branch "4.2" when I pull, as I do when I clone? Something's clearly not identical.

tmp$  mkdir some_repo  tmp$  cd some_repo  some_repo$  git init Initialized empty Git repository in /tmp/some_repo/.git/  some_repo$  git pull https://github.ourplace.net/babelfish/some_repo.git   : From https://github.ourplace.net/babelfish/some_repo  * branch            HEAD       -> FETCH_HEAD  some_repo$  git branch * master 

vs

tmp$  rm -rf some_repo  tmp$  git clone https://github.ourplace.net/babelfish/some_repo.git Cloning into 'some_repo'...   : Checking connectivity... done.  tmp$  cd some_repo  some_repo$  git branch * 4.2 


回答6:

While the git fetch command will fetch down all the changes on the server that you don’t have yet, it will not modify your working directory at all. It will simply get the data for you and let you merge it yourself. However, there is a command called git pull which is essentially a git fetch immediately followed by a git merge in most cases.

https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches#Pulling



回答7:

clone: copying the remote server repository to your local machine. pull: get new changes other have added to your local machine.. This is the difference. Clone is generally used to get remote repo copy.. pull is used to view other team mates added code, if you are working in teams.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!