🏠

Dot files managed in (bare) git repo

Published on 2025-04-11

I manage my dotfiles (mainly configs (including my custom eurokey config), but also some scripts and desktop files) by using a bare git repo to keep them version-controlled and easily portable. I didn’t invent this method—for a deep dive check out Atlassian’s tutorial.

What is a bare git repository and why do we want to use that? A bare Git repository contains only version control information without a working directory. We use it in this case because it avoids conflicts with existing directories, allows your home directory to serve as the working tree, and enables tracking files in their original locations without symlinks or nested repositories.

Setup instructions

  1. Initialize a bare git repo: git init –bare <some_location>, e.g. git init –bare /home/$USER/.local/dotfiles
  2. Create a git alias depending on your shell:

    • Fish: abbr -a cfg ’git –git-dir=<some_location> –work-tree=$HOME’ (add this to your fish config to persist it)
    • Bash: alias cfg=’/usr/bin/git –git-dir=<some_location> –work-tree=$HOME’ (similarly, add this to your .bashrc to persist it)
  3. Hide untracked files (so Git doesn’t show everything in your home directory): cfg config –local status.showUntrackedFiles no
  4. Backup to a remote repository:

    • Create an empty Git repo on your preferred Git hosting provider.
    • Add it as a remote: git remote add origin <your_repo>
    • Push your current dotfiles: git push -u origin main

That’s it! You can now use cfg instead of git to manage your dot files.

Bonus: To get notified of uncommitted changes every time you open a new shell, add this to your Fish config:

if status is-interactive
    # Commands to run in interactive sessions can go here
    git –git-dir=<some_location> –work-tree=$HOME status –porcelain
end

To set up the dotfiles on a new machine, you can simply create the alias and do git clone –bare <your_repo> <some_location>, and your personalized environment is ready to go.