Make a “copy” of another repo.

Fetches all the remote branches.

Creates only a single branch: the branch were the HEAD of the remote was, but also fetches all other branches under .git/refs/origin/, so that you can just git checkout -b other-branch to create them.

Example: clone and branches

Start with multi.

git clone a c

Creates a repo c that is a “copy” of a. Now:

cd c
branch -a
    #master *

So you only have one branch, and the other are remote heads.

But if you do:

cd a
git checkout b
cd ..
git clone a d
cd d
git branch -a
    #b *

Then you have a b branch, because that is where the head was when you cloned.

Clone from GitHub

It can also clone from a server such as GitHub:

git clone newname

This is how you download a project which interests you.


Shallow clone

Clone only the N most recent commits and the working tree.

Has / had some limitations. But still, should only be used for CI and deployment.


git clone jquery
git clone --depth 1 jquery_shallow
cd jquery_shallow
git log

jquery_shallow is much smaller and the clone was much faster. But git log only shows the last commit for it.

For local clones, this can only be observed if you use file:// as protocol: objects are just hardlinked otherwise if possible. --no-hardlinks changes nothing.

mkdir server
cd server
git init

for i in a b c; do
    touch "$i"
    git add .
    git commit -m "$i"

cd ..
git clone --depth 1 "file://$(pwd)/server" local
cd local
git log
comments powered by Disqus