Nan Xiao Nan Xiao - 1 year ago 129
Git Question

How can I clone a module from linux kernel?

If I only want to focus on a module of

, such as
, how can I just fork or download
module related files from github? I have tried the following command:

c:\work> git clone
Cloning into 'perf'...
fatal: repository '' not found

But it can't work.

Answer Source

You need to use a combination of two relatively new features of Git.

The first is sparse-checkout (available since Git 1.7.0). Sparse-checkout allows you to keep your workspace clean by explicitely specifying which directories you want to have in your repo. However it does not affect the size of the whole repository and downloading 1GB of all Linux kernel sources is pain in the neck. That's why you need the second feature:

The second feature is shallow clone (available since Git 1.9.0). It allows you to pull from a repo keeping only n changesets in the history using --depth parameter.

So if you want to get only the tools/perf module this is the way to go:

git init
git remote add origin
git config core.sparsecheckout true
echo "tools/perf" >> .git/info/sparse-checkout
git pull --depth=1 origin master

Voila! The only directory in your repo is tools/perf and you had to download only 136MB.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download