Skip to content

Instantly share code, notes, and snippets.

@emildimitrov
Created September 18, 2022 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emildimitrov/8775922c32a68c4971925a008ddb90f6 to your computer and use it in GitHub Desktop.
Save emildimitrov/8775922c32a68c4971925a008ddb90f6 to your computer and use it in GitHub Desktop.
Dotfiles bare repo setup

Dotfiles with bare git repository

Why bare repository

Traditional dotfiles management is relying on keeping you repository in sync with the OS dotfiles via symlinks which is not ideal. Bare repo is solving that, because it enables us to keep the tracked files (working tree) separate from the internals (.git folder) In our case the working tree will be $HOME and the internals will be in $HOME/projects/dotfiles.git

Setup

Add in your shell config the following

export DOTFILES=$HOME/projects/dotfiles.git
#setup alias to link .git dir to $DOTIFILES and the working tree to $HOME
alias cfg='git --git-dir=$DOTFILES --work-tree=$HOME'

From now one we will use cfg instead of git when it comes to managing config files (dotfiles)

Make sure that untracked files are not showing - we want to pick only what we need for git persistance cfg config status.showUntrackedFiles no

Now edit some of your config files and cfg add <yourfile> and cfg commit -m <message>

Now you can persist to github or other git storage your changed configs

For github most proably you'll need to add you remote cfg remote add origin git@github.com:<username>/dotfiles.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment