How to manage your [dot] files with git. First of all what is dotfiles ? For those who don’t konw dotfiles is configuration files inside your home directory file names and directories starts with a “.” thats why it’s called dotfiles.
The problem ?
- I want to manage it with a git repositry
- I don’t want to mess with all files inside home directory as untracked git files
it was simple and plain in terms of linux way
Choose directory where your repository will be stored for instance ~/Dotfiles
Got inside and make git bare repostory
git init --bare .
Bare repository is repository without a working directory so it’s contains of git internals structure itself to store objects added to repostory
You better know what is bare git repository here
Setup special alias for git command to work with ~/Dotfiles
alias dotfiles='/usr/bin/git --git-dir=$HOME/Projects/Personal/Dotfiles/ --work-tree=$HOME'
Make this alias permanent by adding it to your .bashrc or .zshrc configuraton
Make git stop showing untracked files
dotfiles config status.showUntrackedFiles no
Step 5 Finally
dotfiles add ~/.zshrc
dotfiles -m "Add zsh configuraton"
That’s it. If you want to push to remote add origin before and push it same way
dotfiles add origin URL
dotfiles push origin master
Since dotfiles is special alias for git you can do
dotfiles status when editing your configs to see what files have been changed.
Why this is good solution ?
If you’re mind to store configs as usual and just create simple directory to store it, you have to deal with setup process to actually update files on their location in system, using this method you don’t need to think about install and deploy.
When you do
dotilfes ls you don’t have to deal with other files which is not been added to repository and are not dot files you’re interested in.