Git worktrees and kernel development

Some time ago, I read something and decided to give the “git worktree” command a try.

I should have done it a long time ago…

Linux kernel trees

I have a feeling that each SBC which has landed on my desk has required some kernel work. This involved fetching things from the mainline, the distro kernel, other distro kernels, SoC-specific trees, etc.

In the end, I ended up with several git trees copied into the “~/devel/sources/linux/” directory, and used this setup for most of my kernel-related activities.

$ git remote update
Fetching centos-stream-10
Fetching centos-stream-9
Fetching colabora-hwe-rk3588
Fetching debian
Fetching fedoravforce-cs-10
Fetching hrw-cs10
Fetching hrw-cs9
Fetching hrw-kernel-ark
Fetching hrw-rhel9
Fetching kernel-ark
Fetching linux-next
Fetching linux-rockchip
Fetching rhel-10
Fetching rhel-9
Fetching stable
Fetching torvalds

Git worktree

One day, I was reading about Git and found the “git worktree” command, which allows me to manage multiple working trees attached to the same repository. So, I decided to give it a try. At first, I moved the git repository from “~/devel/sources/linux/” to the “~/devel/sources/linux/git/” directory, in order to leave the parent directory as the base for all trees.

This year, most of my kernel-related work is focused on backporting patches to RHEL kernels. So I started creating separate working trees:

git worktree add ../ark
git worktree add ../centos-stream-10
git worktree add ../centos-stream-9
git worktree add ../torvalds

This way, I have a separate copy of Fedora’s “Always Ready kernel”, the CentOS Stream 9/10 kernels and a copy of Linus Torvalds’ tree.

When I go back to hacking a RK3588 (as the FriendlyELEC SBC awaits), I will create a separate working tree especially for it.

With this set of working trees, I can easily compare files and their history between branches and keep each kernel tree separated from the others.

Workflow

For example, my recent work on backporting NVIDIA Tegra patches involved cherry-picking patches from the mainline kernel into the CentOS-Stream-10-based branch.

Then, there was a kernel config change which I had to make in Fedora’s ARK tree first, and then synced it to my CS10 branch.

With separate working trees, there was no need for constant switching between git branches.

Conclusion

As I wrote before, use of “git worktree” is something I should have done a long time ago. It saves me a lot of time and allows me to look at different versions of the same file in one editor window.

centos development git kernel red hat