GIT Cloning of branches

GIT is pretty powerful. I use it on a daily base at the moment. Furthermore I watch the mailinglist. Therefore I discovered a simple workflow that is not yet implemented nicely in GIT: cloning of a particular branches.

I wanted to clone the cvs-imported PHP_5_3 branch of PHP, which is provided by Johannes Schlüter. But at the moment git-clone just supports cloning of complete repositories. So I asked myself how do clone just a certain branch. At the same time somebody came up with a similar issue at the git mailinglist. Linus came up with a simple batch of commands (git-remote, etc) to be executed to get the result.

I finally decided to write a small git-clone-branch.sh script which does this job, supporting multiple branches to be cloned from a certain repository.The script is available from my personal git repository that contains personal changes as well as the current maintainer branch of git. If you want to get the script, just clone the repository, compile and install the dsp branch. After that you will have the command git-clone-branch (without documentation at the moment).

To clone a certain branch (e.g. the dsp branch) just use the command:

$ git-clone-branch http://git.experimentalworks.net/git.git dsp

You can use multiple branches to fetch by just adding them at the end of the command (cloning dsp and master branch from the repos):

$ git-clone-branch http://git.experimentalworks.net/git.git dsp master

You can also use the -d <DIR> option to create the clone into the given DIRECTORY.

The next step will be to include this peace of code into the git-clone command, but it will require a lot of work, as this change will be a good starting point to rewrite git-clone using the new git-remote command. But this will take a few hours. Maybe I’ll do this in the next days, submitting the finished patch to the mailinglist. But at the moment, you have to use git-clone-branch.

If you have suggestions or added some features or a documentation about that command, just drop me a line at sn_ at gmx dot net

2 Comments

  1. gebi says:

    please do _NOT_ pack repositories to which you only provide http access…

    users wanting to add your git repos as remote to the upstream git repos have to download nearly 17MB only to get your few commits.

    try it yourself:
    git clone git://git.kernel.org/pub/scm/git/git.git
    cd git
    git remote add you http://git.experimentalworks.net/git.git
    git remote update

  2. dsp says:

    Okay sorry, I’ll change this today.

Leave a Reply