Skip to content

Instantly share code, notes, and snippets.

@ennanco
Last active April 4, 2025 07:21
Show Gist options
  • Save ennanco/d1c6a228f5aac23a3af6592135f0f8ae to your computer and use it in GitHub Desktop.
Save ennanco/d1c6a228f5aac23a3af6592135f0f8ae to your computer and use it in GitHub Desktop.
Managing the dotfiles with style (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/.cfg
    git init --bare $HOME/.cfg
  1. Create an alias for a better managing of the configuration
    alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --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
   config 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
   config remote add origin <remote-url>
   config 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 ".cfg" >> .gitignore 
  1. Clone the remote repository
   git clone --bare <remote-git-repo-url> $HOME/.cfg 
  1. Restore the alias and configuration of tracking
    alias config='/usr/bin/git --git-dir=$HOME/.cfg --work-tree=$HOME'
    config config --local status.showUntrackedFiles no
  1. Proceed to checkout
config checkout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment