Dotfiles with Bare Git Repo
This guide provides a robust method for backing up and managing your configuration files (dotfiles) using a bare Git repository. This technique allows you to version control files directly in your $HOME directory without turning the entire directory into a repository.
Quick Start (Speedrun)
Section titled “Quick Start (Speedrun)”For experienced users, here’s the quick setup:
# Configure gitgit config --global user.name "your-name"git config --global user.email "your-email@example.com"git config --global init.defaultBranch main
# Initialize bare repogit init --bare $HOME/dusky
# Configure to hide untracked filesgit_dusky config --local status.showUntrackedFiles no
# Add your files and commitgit_dusky_add_listgit_dusky commit -m "Initial Commit: Fresh Dotfiles Backup"Part 1: Initial Setup
Section titled “Part 1: Initial Setup”Step 1: Configure Git Identity
Section titled “Step 1: Configure Git Identity”Set up your global Git identity:
git config --global user.name "your-name"git config --global user.email "your-email@example.com"git config --global init.defaultBranch mainStep 2: Initialize the Bare Repository
Section titled “Step 2: Initialize the Bare Repository”Create a hidden Git repository in your home directory:
git init --bare $HOME/duskyStep 3: Create the git_dusky Alias
Section titled “Step 3: Create the git_dusky Alias”Add this alias to your ~/.zshrc or ~/.bashrc:
alias git_dusky='/usr/bin/git --git-dir=$HOME/dusky/ --work-tree=$HOME'Reload your shell:
source ~/.zshrcStep 4: Configure Repository Status
Section titled “Step 4: Configure Repository Status”Hide untracked files to keep git status output clean:
git_dusky config --local status.showUntrackedFiles noStep 5: Track Your Dotfiles
Section titled “Step 5: Track Your Dotfiles”Add files you want to track:
git_dusky add ~/.zshrcgit_dusky add ~/.config/hypr/git_dusky add ~/.config/waybar/# Add more as neededMake your first commit:
git_dusky commit -m "Initial Commit: Fresh Dotfiles Backup"Part 2: Remote Backup
Section titled “Part 2: Remote Backup”Step 1: Create Remote Repository
Section titled “Step 1: Create Remote Repository”Create a new, empty repository on GitHub. Do not add a README, .gitignore, or license.
Step 2: Configure SSH Authentication
Section titled “Step 2: Configure SSH Authentication”ssh-keygen -t ed25519 -C "your-email@example.com"eval "$(ssh-agent -s)"ssh-add ~/.ssh/id_ed25519cat ~/.ssh/id_ed25519.pubAdd the public key to GitHub: Settings > SSH and GPG keys > New SSH key
Step 3: Link and Push
Section titled “Step 3: Link and Push”git_dusky remote add origin git@github.com:username/dusky.gitgit_dusky branch -m maingit_dusky push -u origin mainTest the connection:
ssh -T git@github.comPart 3: Restore on New System
Section titled “Part 3: Restore on New System”Deploy your dotfiles onto a fresh installation:
# Clone the bare repogit clone --bare --depth 1 https://github.com/username/dusky.git $HOME/dusky
# Checkout files to home directory/usr/bin/git --git-dir=$HOME/dusky/ --work-tree=$HOME checkout -fMaintenance
Section titled “Maintenance”Adding New Files
Section titled “Adding New Files”git_dusky add ~/.config/new-app/configgit_dusky commit -m "Add new-app config"git_dusky pushRemoving Tracked Files
Section titled “Removing Tracked Files”To stop tracking a file without deleting it:
git_dusky rm --cached ~/.config/old-filegit_dusky commit -m "Stop tracking old-file"