Linux Kernel Development Using Git

This article looks at setting up Git and using it for Linux kernel development. It is aimed at developers who would like to move their development environment to Git SCM. I assume that readers are well versed with source-control software.

Git is a powerful source-code-control software. Its fundamental design goal was “high performance”. Earlier, Linux kernel development used a free version of a proprietary software called BitKeeper. Later, when BitKeeper stopped being free, Linus Torvalds came up with the idea of Git (Global information tracker). He was the initial author of the software, and later it was passed to Junio Hamano. Linus has a special need for high-performance software, due to the volume of kernel patches he handles, and Git was the answer. The major advantage of Git is that it need not be connected to a server for committing code.

Prerequisites

You need to have Git downloaded and installed on the host machine (I am using Ubuntu Maverick). If you are using Ubuntu, you can simply issue the command sudo apt-get install git-core. Once installed, Git can be used as a regular user, and does not need super-user privileges.

Configuring Git

The git config command is used to set the Git repository options. The following examples are the most common options you need to set before you perform a code commit:

The --global option saves these options in the user’s home directory, in the file ~/.gitconfig.

If you need to manipulate a specific repository’s settings, instead of the global options, you need to cd into the repository directory, and issue the above commands without the --global switch. This will save the options in the config in the .git directory within the repository. System-wide changes can also be performed if the --system tag is used. For more options, refer to th man page with man git-config.

The Linux kernel with Git

Let’s concentrate on setting up your Linux kernel repository using Git. The Linux kernel has multiple Git repositories online. In fact, architectures like arm maintain their own Git repository. Here, let’s try syncing up with Linus Torvalds’ linux-2.6 Git repository. You can obtain information about other repositories from kernel.org.

Linus Torvalds’ repo can be cloned to your local machine using the following command:

Refer this URL for more linux-2.6 URLs. Depending on your Internet connection speed, it could take quite some time to download the whole kernel repository.

Git uses port 9418 for communication with the Git server. If you are behind a corporate firewall, the above will not work. For this reason, developers have provided an alternate URL to be used over HTTP port 80:

Note: In case you have to go out via a proxy server, do not forget to set and export the proxy server address in the environment variable http_proxy, which Git uses, e.g, export http_proxy=http://your-corporate-proxy.com/:<port>.

The clone command creates a directory named linux-2.6 in your current directory.
To update your repository, use the command git pull. This downloads all new commits since the last git pull. Once this is done, you can work on your local copy without needing an Internet connection. Use git pull as follows:

$ cd linux-2.6
$ git pull

The above command will automatically use the original source URL to pull updates. To view the URL that is being used, run cat linux-2.6/.git/config.

Working with your local copy

Once you have your local copy, you can create your own branches, modify code, and apply your changes back. Let’s explore a few commands to familiarise ourselves with Git usage. To list all branches in the current repository, issue the command given below:

$ git branch

The current branch will have a * before it. The command git status also shows the current branch. To create a new branch, and make it the working branch, use the following command:

$ git checkout -b new_branch

To jump from the current branch to a new branch, use the code given below:

$ git checkout new_branch

To change code and commit it into our local repository, the general steps are as follows:

If you have done a lot of changes, but not performed a commit yet, and want to flush them off the branch, try the command that follows:

$git checkout -f

If you have already committed, and want to get rid of the commit, use the following code;

$ git reset HEAD~1 ## last commit is removed

Contributing to Git development

Git’s core development is done with Git itself. It is still in active development, and hence commits are actively pushed. The latest commits can be viewed on the Web at git://git.kernel.org/pub/scm/git/git.git. You can clone the latest copy with the following command:

$ git clone git://git.kernel.org/pub/scm/git/git.git

If you think you can contribute to Git development, clone your copy, and start working on it!

This article covers the most commonly used set of Git commands. For more information and advanced usage, refer to The Git Community Book. It is not an absolute must that you use Git to do kernel development, but like any other tool, it helps you speed up your work, and allows you to concentrate on the actual patch rather than on how to create a patch.

The author is an engineering advisor in the Product Group at Dell India R&D Centre, Bengaluru, and has eight years of experience in Linux. He spends most of his time hacking and playing around with Linux.

Can some one please tell me how to create clone form downloading source code “linux-3.12.2.tar.xz” file.. i am new to this and my internet ll take days to download d clone by using “git clone” command..

POPULAR CATEGORY

Open Source For You is Asia's leading IT publication focused on open source technologies. Launched in February 2003 (as Linux For You), the magazine aims to help techies avail the benefits of open source software and solutions. Techies that connect with the magazine include software developers, IT managers, CIOs, hackers, etc. A free DVD, which contains the latest open source software and Linux distributions/OS, accompanies each issue of Open Source For You. The magazine is also associated with different events and online webinars on open source and related technologies.