This setup allows for managing configuration files (dotfiles) directly in the
$HOME directory using Git, without the need for symlinks, specialized
management tools, or messy directory structures.
The core of the system is a bare Git repository located at ~/.dotfiles/.
Unlike a standard repository, a bare repo doesn't have a default working
directory. We manually point its "working tree" to $HOME using a simple shell
alias.
Add this to your .bashrc or .zshrc:
alias dot='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'To prevent Git from showing every untracked file in your home directory (which
would make dot status unusable), we configure the repository to ignore
untracked files by default:
dot config --local status.showUntrackedFiles no- Zero Symlinks: Files live in their natural locations (e.g.,
~/.bashrc,~/.gitconfig). You don't need to manage a complex tree of symlinks or use tools like GNU Stow. - Native Git Experience: Since
dotis just a standard Git command with specific flags, all your existing Git knowledge applies (dot status,dot add,dot commit,dot diff, etc.). - Portable & Lightweight: This works on any system with Git installed. No Python, Ruby, or Node.js dependencies are required.
- Clean Workflow: Only files you explicitly
dot addare tracked. The rest of your home directory remains invisible to Git.
dot add ~/.bashrc
dot commit -m "Add bashrc to dotfiles"dot status
dot diffdot push origin main
dot pull origin main- Clone the repo as a bare repository:
git clone --bare <your-repo-url> $HOME/.dotfiles
- Define the alias in your current shell session:
alias dot='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
- Checkout the content into your home directory:
dot checkout
- Silence untracked files:
dot config --local status.showUntrackedFiles no