How to obtain and manage kernel source for an Ubuntu release using Git¶
The kernel source code for each Ubuntu release is maintained in its own repository in Launchpad. Downloading the kernel source may be needed for customization, development, or troubleshooting the kernel.
This document shows how you can obtain and manage the kernel source for an Ubuntu release using Git.
Prerequisites¶
You must have the git package installed on your system.
sudo apt-get install git
Get local copy of kernel source for single release¶
You can use git clone with the selected protocol to obtain a local copy of
the kernel source for the release you are interested in.
For example, to obtain a local copy of the Jammy kernel tree, run any of the
following git clone commands:
git clone git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/jammy
git clone git+ssh://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/jammy
git clone https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/jammy
See Protocols for accessing kernel sources for more information.
Add multiple series as remotes¶
If you are an advanced Git user, you can add each Ubuntu series as a remote to have all kernel series in a single Git repository, and switch between them using branches:
git remote add jammy https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/jammy
git fetch jammy
git checkout -b jammy --track jammy/master
git checkout -b jammy-next --track jammy/master-next
Work with multiple series in separate subdirectories¶
To have the source for each kernel series available in its own subdirectory
within a single Git repository, use git subtree add:
git subtree add --prefix=jammy https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/jammy master
git subtree add --prefix=noble https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/noble master
This creates a jammy/ subdirectory containing the Jammy kernel source and a
noble/ subdirectory containing the Noble kernel source, all within the same
repository.
To pull future updates into a subtree, specify the remote URL and ref explicitly - there is no automatic upstream tracking for subtrees:
git subtree pull --prefix=jammy https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/jammy master