tags:

views:

98

answers:

2

What is the difference between doing:

mkdir repo
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?

+2  A: 

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.

meagar
git fetch --all sets up additional remote tracking branches, so basically they are the same.
cmcculloh
+1  A: 

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).

ebneter
What specifically is it that git clone is doing that isn't accomplished by the sequence of commands that involved "git pull"?
cmcculloh
@cmcculloh: Nothing -- the sequence you describe effectively accomplishes what "git clone" does. The point is that "git pull" is used to do a variety of things beyond what you did there -- not to mention that "git pull" is actually exactly the combination of "git fetch; git merge <current branch> <origin/current branch>". IOW, you could live without clone *and* pull if you really wanted to. Further, you can pull from repositories other than the one you cloned from.I like to think of 'clone' as "make me a local copy of that repo" and 'pull' as "get me the updates from some specified remote."
ebneter