Posted on September 11, 2016
Tags: nerd, git, nix

I was pleased to find out about the git-worktree command while reading the Git v2.10.0 release notes.

It lets you have a single full clone of a git repo, but multiple checkouts in different places. It saves a little disk space because the .git directory is shared. But more importantly, it’s more convenient because you don’t need to be always running fetches and pushes between your clones.

I was previously using the git-new-workdir script from the contrib directory of the git.git repo, but it did always seem slightly dangerous and not an officially blessed usage of git.

The main reason for this post is to point out that git-worktree is extremely helpful for nixpkgs contributors because you can keep one worktree for your running NixOS systems and use the main clone for developing pull requests, etc.

Pull requests are usually based off the master branch, which can be unsuitable for installing, if only for the reason that prebuilt binaries aren’t always available.

The running systems work tree would probably have one of the channel branches checked out. This can be updated independently of your development activities.

I have my main nixpkgs clone in ~/dev/nixpkgs and the running systems work tree in ~/ops/nixpkgs. In configuration.nix, I point NIX_PATH to the work tree like this:

  nix.nixPath = [
   "/home/rodney/ops"
   "nixos-config=/home/rodney/ops/laptop/configuration.nix"
   "/nix/var/nix/profiles/per-user/root/channels/nixos"
  ];

Nix is a success in its own right, but I think git multiplies its power. Other version control systems are clunky in comparison to git.