Skip to content

Instantly share code, notes, and snippets.

@viscount-monty
Forked from ennanco/Dotfiles_backup.md
Last active December 29, 2025 01:24
Show Gist options
  • Select an option

  • Save viscount-monty/f4c42fd3790f239ac0ca0c72a742d897 to your computer and use it in GitHub Desktop.

Select an option

Save viscount-monty/f4c42fd3790f239ac0ca0c72a742d897 to your computer and use it in GitHub Desktop.
Managing Linux dotfiles kept in $HOME (git bare repo)

I have recently come accross with a new solution to one of my biggest headaches in any linux system and it is to manage the nightmareof the dot files. I have previously used stow in order to mantain the symbolic links, but there is a much better solution using git bare repositories.

1. Creating the repository

  1. Create a git bare repository with the following line
    mkdir $HOME/.dotfiles
    git init --bare $HOME/.dotfiles
  1. Create an alias for a better managing of the configuration
    alias dc='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'

It should be highlighted that you can put it in your .bashrc or the file you use for your alias, in my case $HOME/.config/aliasrc

  1. Disable the tacking of any single file
   dc config --local status.showUntrackedFiles no
  1. You can use it in a normal basis with config and keywords like "add, delete, status, checkout, ...". Remember to add a remote repositoryy with this lines
   dc remote add origin <remote-url>
   dc push -u origin master

For example you can create a diferent configuration in different branches for each machine that you have.

2. Restore a configuration

  1. Prevent weird circular dependencies
echo ".dotfiles" >> .gitignore 
  1. Clone the remote repository
git clone --bare <remote-git-repo-url> $HOME/.dotfiles 
  1. Restore the alias and configuration of tracking
alias dc='/usr/bin/git --git-dir=$HOME/.dotfiles --work-tree=$HOME'
dc config --local status.showUntrackedFiles no
  1. Proceed to checkout
dc checkout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment