How to Install and Use dura in Linux for Automatic Background Git Commits

Losing uncommitted code due to sudden hardware crashes, accidental power loss, terminal resets, or destructive git commands (such as git reset --hard or git checkout -f) is a major frustration for developers. While standard Git workflows require manual staging and committing, dura is a background monitoring daemon written in Rust that watches your active repositories and automatically creates snapshot commits in the background without altering your current branch, staging area, or git history.

How dura Protects Your Uncommitted Code

Traditional auto-save plugins inside text editors only save changes to local disk files. If an errant script or Git command overwrites those files, editor undo buffers often fail. dura operates at the Git object database level with several key guarantees:

  • Invisible detached branch tracking: dura commits uncommitted working directory changes into hidden, detached references (prefixed under refs/dura/).
  • Zero interference with your workflow: It never updates HEAD, touches your active branch pointer, alters your index (staging area), or affects git status output.
  • Instant point-in-time recovery: Every time you pause typing or save a file, dura commits a lightweight snapshot that you can inspect, diff, or restore at any time.

Installing dura on Linux Distributions

Method 1: Installing via Cargo

If you have Rust and Cargo configured on your machine:

cargo install dura

Ensure that Cargo’s binary directory is included in your system PATH:

export PATH="$HOME/.cargo/bin:$PATH"

Method 2: Installing Pre-compiled GitHub Releases

For systems without a Rust toolchain, install the official compiled binary release:

curl -sSL https://github.com/jonhoo/dura/releases/latest/download/dura-linux-x86_64.tar.gz | tar -xz
sudo mv dura /usr/local/bin/
sudo chmod +x /usr/local/bin/dura

Method 3: Arch Linux (AUR)

On Arch-based distributions, install using your AUR helper:

paru -S dura-bin

Starting and Enabling the Background Daemon

dura must run continuously in the background to monitor file modifications. You can run it manually or configure it as a user-level Systemd daemon.

Enabling Systemd User Service (Recommended)

Run the built-in system service generator:

# Start the background service immediately
dura serve &

# Or integrate with systemd
systemctl --user enable --now dura

Watching Repositories for Automatic Commits

By default, dura does not monitor all repositories on your system; you explicitly mark target projects for active tracking.

Adding a Repository to Watch List

Navigate into your target Git repository and execute:

cd ~/projects/my-web-app
dura watch

The daemon records the directory path into its configuration file located at ~/.config/dura/config.json. Whenever any file within ~/projects/my-web-app changes, dura commits a snapshot after a brief idle delay (default: 5 seconds).

Command Action Performed Target Use Case
dura watch Registers current repository for continuous snapshots. Active development workspaces.
dura unwatch Removes repository from active background tracking. Archived or third-party repositories.
dura capture Forces an immediate one-off snapshot commit. Pre-build scripts, automated CI/CD steps.
dura kill Terminates the running background daemon. Maintenance and service restarts.

Recovering Lost Code from dura Snapshots

If you accidentally discard changes using git reset --hard HEAD or delete an uncommitted file, you can restore your work from dura‘s internal commit history.

1. Listing Historical Snapshots

Inspect the snapshots captured for your current working branch:

git log --oneline $(git rev-parse --abbrev-ref HEAD) dura/$(git rev-parse --abbrev-ref HEAD) -n 10

Or list the specific reflog for dura:

git log --stat -n 5 refs/dura/$(git rev-parse --abbrev-ref HEAD)

2. Restoring a Specific File

To pull back a single lost file from the latest background snapshot without altering other working files:

git checkout refs/dura/$(git rev-parse --abbrev-ref HEAD) -- src/components/Header.jsx

3. Diffing Active Changes Against Latest Snapshot

git diff refs/dura/$(git rev-parse --abbrev-ref HEAD)

Troubleshooting Common dura Issues

  • Snapshots not being created: Verify that the daemon is active using pgrep dura. If no process ID returns, start it using dura serve & or inspect dura status.
  • Large untracked build artifacts: dura respects your repository’s .gitignore rules. Ensure large assets (such as node_modules/, binary outputs, or virtual environments) are properly declared in .gitignore to prevent bloat in the Git object database.
  • Pruning old snapshots: Because dura stores snapshots as standard Git objects, standard garbage collection cleans unreferenced objects over time:
    git gc --prune=now

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.