Skip to content
Advertisement

How can I clone a module from linux kernel?

If I only want to focus on a module of linux, such as perf, how can I just fork or download perf module related files from github? I have tried the following command:

c:work> git clone https://github.com/torvalds/linux/tree/master/tools/perf
Cloning into 'perf'...
fatal: repository 'https://github.com/torvalds/linux/tree/master/tools/perf/' not found

But it can’t work.

Advertisement

Answer

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 https://github.com/torvalds/linux.git
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.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement