A clever way to manage your dotfiles with GIT2020-04-10
This method is inspired by an Article from Atlassian, which again is inspired by a thread on Hacker News.
I find this method very clever and elegant, and I just want to document my onw setup:
- Your dot files live in your home directory, as they always will - no links or other hacks needed
- The get versioned with git, and can be shared with other hosts using a central repo.
Initial setup (no repo created yet)
Init a bare repo in your home folder:
# Create a bare repo: $ git init --bare $HOME/.dotconfig # add an alias for the git command, using your home folder as work tree: $ alias dotconfig='/usr/local/bin/git --git-dir=$HOME/.dotconfig/ --work-tree=$HOME' # do not track un-added files $ dotconfig config --local status.showUntrackedFiles no
- Use the
dotconfig
command to manage your dotfiles:sh $ dotconfig status $ dotconfig add .zshrc $ dotconfig commit -m "Add zshrc" $ dotconfig add .config/nvim/init.vim $ dotconfig commit -m "Add neovim config" $ dotconfig push
- Use the
Install to a new system / migrate to an existing one
Make sure you set up the following steps BEFORE cloning the repo:
$ alias dotconfig='/usr/local/bin/git --git-dir=$HOME/.dotconfig/ --work-tree=$HOME' $ echo ".dotconfig" >> .gitignore
- Clone the dotconfig repo:
sh $ git clone --bare [your-repo-url] $HOME/.dotconfig
- Clone the dotconfig repo:
Checkout the actual content from the bare repo:
$ dotconfig config --local status.showUntrackedFiles no $ dotconfig checkout
- If there are existing dotfiles that conflict with the ones from your repo, you have to move them first. With this technique managing your local dotfiles on multiple machines with version history become really simple.