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
Solution
I’ve started search for solution and it gets me to this article Method it self as it mention in article has been proposed on hacker news
it was simple and plain in terms of linux way
Step 1
Choose directory where your repository will be stored for instance ~/Dotfiles
Step 2
Got inside and make git bare repostory
cd ~/Dotfiles
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
Step 3
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
Step 4
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...