Skip to content

James Williams

How to convert a subdirectory to its own git repository/submodule

# Make a clone of the repository
git clone <your_project> <new_submodule>

# CD into the new repository
cd <new_submodule>

# Use filter-branch to isolate the subdirectory
git filter-branch --subdirectory-filter 'path/to/subdirectory' --prune-empty -- --all

# Remove the old remote
git remote rm <remote_name>

git filter-branch lets you rewrite Git revision history and apply custom filters on each revision. It should be used with caution! From the Git Manual (emphasis mine):

git filter-branch has a plethora of pitfalls that can produce non-obvious manglings of the intended history rewrite (and can leave you with little time to investigate such problems since it has such abysmal performance). These safety and performance issues cannot be backward compatibly fixed and as such, its use is not recommended.

Nevertheless, since we live dangerously around these parts, here’s what’s happening with the filter-branch command should you choose to use it:

  • --subdirectory-filter is the main command. It takes a path to a subdirectory and filters the repository to only include that subdirectory.
  • --prune-empty removes commits that don’t change anything.
  • -- --all is a way to pass arguments to the internal git rev-list command. In this case, it’s telling git to run the command on all branches.

Once the operation is done, you’ll have a new repository with only the subdirectory you specified. You can then push it to a new remote and add it as a submodule to your original repository.

git filter-branch is a destructive operation. While I’ve used the above command with success on my own repositories, your mileage may vary and I probably can’t help you if something goes wrong.

GPG Field Guide

Jürgen Gmach on his personal blog:

While I need to use GPG pretty regularly, I always have to look up the commands - they just don’t stick :-)

Over the last couple of months I collected every command I had to use. Enjoy!

🔖 One for the bookmarks: GPG - All I Need to Know

I'm in love with Guanajuato

Guanajuato City facing south from Centro

Lens Model iPhone 14 Pro back triple camera 6.86mm f/1.78
ISO 80
Exposure Time 1/121
Image Size 4032x3024
GPS Position 21.018317 N, 101.253494 W
GPS Altitude 2058.7 m Above Sea Level
GPS Img Direction 159.2975464
Create Date 2023:01:03 18:22:08

Guanajuato City is located in a narrow valley surrounded by mountains, and is known for its narrow, winding streets, sharp topography and colorful houses. One of the most unique features of Guanajuato is its network of underground tunnels. The city has a spooky vibe and I absolutely love it.

How to configure a python script as the default build task in VS Code

This snippet goes in your .vscode/tasks.json file. It will run the current python file as the default build task.

  • command will invoke the python interpreter that is configured in your workspace settings.
  • group will make this task the default build task.
  • presentation:focus will focus the terminal window when the task is run.
  • presentation:reveal will reveal the terminal window when the task is run.

Change args to any python file if you’d like to run the same file each time.

  // See
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
      "label": "Python: current file",
      "type": "shell",
      "command": "${command:python.interpreterPath}",
      "args": ["${file}"],
      "problemMatcher": [],
      "group": {
        "kind": "build",
        "isDefault": true
      "presentation": {
        "focus": true,
        "reveal": "always"
      "options": {
        "cwd": "${workspaceFolder}"

Introducing bulletproof-python

I owe a debt of gratitude to Claudio Jolowicz for introducing me to modern python tooling. His Hypermodern Python template and associated blog series are a great resource.

The Hypermodern system is built around nox and poetry.

  • nox is similar in spirit to tox but uses python scripts instead of configuration files.
  • It’s very powerful, but since I’m not particularly clever, I find the hypermodern stack difficult to understand.

I decided to throw together a simple template that uses tox and pip-tools. The template uses:

It strives to be clean, simple and hard to break, albeit incomplete and likely suitable only for small libraries without broad distribution.

🌱 The template is available here: bulletproof-python.